LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 08-18-2009, 01:29 PM   #1
homer_3
Member
 
Registered: May 2008
Posts: 85

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,
etc...
<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, 01:57 PM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
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>'
Example:
Code:
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:
http://www.grymoire.com/Unix/Sed.html
 
  


Reply


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 05:10 AM
Yet more sed, this time with regex! MasterC Linux - Software 4 08-16-2007 03:45 PM
sed RegEx problems InJesus Programming 6 01-12-2007 11:48 AM
sed / regex question whysyn Linux - General 3 06-28-2005 02:11 PM
Help with Sed and regex cmfarley19 Programming 6 11-18-2004 01:09 PM


All times are GMT -5. The time now is 07:32 PM.

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