LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 11-21-2011, 11:35 PM   #1
rramesh1
LQ Newbie
 
Registered: May 2011
Posts: 14

Rep: Reputation: 1
Help to replace a pattern with sed or awk


Hello,

I am trying to find the best way to replace a pattern in the below line:

Original Line:

./begintraffic -i eth0 -R radius -c 1000 -w testreport.data -m live -I all

After search & replacement it should look like

./begintraffic -i eth0 -R radius -c 1000 -w /home/test/run/testreport.data -m live -I all


Please note:

1) there may be more than one whitespace character after "-w" and the option can be anywhere in the line.

I am trying with awk, but I am unable to find the right expression to match the pattern.Can anyone please help to get the right pattern matching expression with either sed or awk to achieve this?


/Ramesh
 
Old 11-22-2011, 12:02 AM   #2
jimtony
Member
 
Registered: Jan 2011
Location: Shanghai,China
Distribution: fedora
Posts: 73
Blog Entries: 1

Rep: Reputation: 2
Use the following command:
Quote:
sed 's/testreport.data/\/home\/test\/run\/testreport.data/'
 
Old 11-22-2011, 12:06 AM   #3
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,502

Rep: Reputation: 1893Reputation: 1893Reputation: 1893Reputation: 1893Reputation: 1893Reputation: 1893Reputation: 1893Reputation: 1893Reputation: 1893Reputation: 1893Reputation: 1893
Or to make it a little easier to read:
Code:
sed -r 's@(testreport.data)@/home/test/run/\1@' file
 
  


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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Awk - pattern for replace (change digit value) webhope Programming 7 04-26-2010 10:15 PM
[SOLVED] Replace pattern in specific lines and column with AWK cgcamal Programming 10 04-26-2010 01:11 AM
replace a pattern with a line using sed/awk lokeshn05 Linux - Newbie 3 05-06-2009 03:01 PM
complicated pattern matching with awk or sed... alirezan1 Linux - Newbie 1 10-10-2008 06:45 PM
How to get the pattern using sed or awk? ahpin Programming 3 08-02-2007 03:16 AM


All times are GMT -5. The time now is 08:58 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