Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 08-18-2009, 02:29 PM   #1
Registered: May 2008
Posts: 88

Rep: Reputation: 15
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?
Old 08-18-2009, 02:57 PM   #2
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
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:


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
regex with sed to process file, need help on regex dwynter Linux - Newbie 5 08-31-2007 06:10 AM
Yet more sed, this time with regex! MasterC Linux - Software 4 08-16-2007 04:45 PM
sed RegEx problems InJesus Programming 6 01-12-2007 12:48 PM
sed / regex question whysyn Linux - General 3 06-28-2005 03:11 PM
Help with Sed and regex cmfarley19 Programming 6 11-18-2004 02:09 PM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:51 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration