Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

scan

macrumors 6502
Original poster
Oct 24, 2005
344
0
I have a ton of files that I have to modified and I haven't done this stuff in years. I have an idea what my sed command should look like

sed '/^<!Blah*.[and then a bunch of stuff i dont' care including new lines]*]>$ d' file

as you can see, i'm not sure what the expression should look like to look for anything including tabs, spaces, new lines, etc

so an example doc would have:

<!blah something something
<something something>
<could have something>
]> //end

I have to delete all those lines.

edit: just a little more clarification. I want to look for something that begins with "<!blah" and delete all the lines until ']>' is found including ']>'
 

ChrisA

macrumors G5
Jan 5, 2006
12,907
2,155
Redondo Beach, California
I have a ton of files that I have to modified and I haven't done this stuff in years. I have an idea what my sed command should look like

sed '/^<!Blah*.[and then a bunch of stuff i dont' care including new lines]*]>$ d' file

try this

sed s/foo/bar/ infile > outfile

In your example line you left of the "s" which is the "substitute" editor command. In your case you want "foo" to match your string you want removes and "bar" to be null Like this "s/foo//" which will remove all the "foos"
foo should be a regular expression that matches what you want removed.

Have you read the sed man page?
 

toddburch

macrumors 6502a
Dec 4, 2006
748
0
Katy, Texas
I don't think you want '/^<!Blah* ...$/, since a match will occur zero or more times (the * quantifier), and thus every line will match, whether it starts with <!Blah or not.

Perhaps you want /^<!Blah+[.]*]>$/

which says: at the start of the line, look for '<!Blah' and it must occur at least once (but can occur multiple times), followed by any character ([.]) any number of times (*), followed by ']>' at the very end of the line.

(I've never used sed, but I am in the midst of reading "Mastering Regular Expressions...) ;)

Not sure of you have to escape the last ] or not.

Check the book and run some tests (or back everything up) before you kick it off.

Todd
 

scan

macrumors 6502
Original poster
Oct 24, 2005
344
0
try this

sed s/foo/bar/ infile > outfile

In your example line you left of the "s" which is the "substitute" editor command. In your case you want "foo" to match your string you want removes and "bar" to be null Like this "s/foo//" which will remove all the "foos"
foo should be a regular expression that matches what you want removed.

Have you read the sed man page?

That is not what I'm looking for. Yes, I've read the man pages. I've used unix for years. Just don't remember sed expressions from back in the day. Thanks anyways.
 

scan

macrumors 6502
Original poster
Oct 24, 2005
344
0
I don't think you want '/^<!Blah* ...$/, since a match will occur zero or more times (the * quantifier), and thus every line will match, whether it starts with <!Blah or not.

Perhaps you want /^<!Blah+[.]*]>$/

which says: at the start of the line, look for '<!Blah' and it must occur at least once (but can occur multiple times), followed by any character ([.]) any number of times (*), followed by ']>' at the very end of the line.

(I've never used sed, but I am in the midst of reading "Mastering Regular Expressions...) ;)

Not sure of you have to escape the last ] or not.

Check the book and run some tests (or back everything up) before you kick it off.

Todd


After working with this for awhile. I think I may have a solution. I think I can only manipulate a line at a time with sed, so I will feed it a script file. Thanks for your help.
 

balamw

Moderator emeritus
Aug 16, 2005
19,365
979
New England
I think I can only manipulate a line at a time with sed, so I will feed it a script file.

I've got a perl script somewhere that essentially does this if you don't find a good solution. (look for a string signifying the beginning of a comment and stop output until the end of the comment is detected.)

B
 

savar

macrumors 68000
Jun 6, 2003
1,950
0
District of Columbia
After working with this for awhile. I think I may have a solution. I think I can only manipulate a line at a time with sed, so I will feed it a script file. Thanks for your help.

Correct: it is not possible to match an expression across a line break with sed.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.