-   Linux - General (
-   -   Help with sed regex (

homer_3 08-18-2009 01:29 PM

Help with sed regex
I'm trying to use sed to remove a debug function from a ton of source files. The function is in the form

REPORT(some args,
<tab> some args,
<tab> some args,
<tab> some args);

I've been trying

sed -i s/'REPORT.*[\r]([\t]*.*[\r])*([\t]*.*)*;'//g file.c

I'm not convinced sed is treating my parenthesis correctly because I think this should work. Anyone good with regexs know of one that will work?

pixellany 08-18-2009 01:57 PM

Your desired pattern match goes across multiple lines, so I think you will need a more precise generic definition. This may be a job for the SED address range syntax. The general form is:
sed '/start/,/stop/<action>'

sed '/dog/,/cat/s/one/two/1' filename > newfilename
This starts on the first line containing "dog", and ends on the first following line containing "cat". In this range, I replaces the first instance of "one" on each line with "two". It writes the results to "newfilename".

In your example, you use "\r". Is that meant to be a return? If so, you want "\n" (newline) instead. BUT: SED works one line at a time so--in your example---multiple newlines will not be matched.

For more and better help, please post an example of the actual text to be removed.

For a really good SED tutorial, go here:

All times are GMT -5. The time now is 03:54 AM.