LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Help to replace a pattern with sed or awk (https://www.linuxquestions.org/questions/linux-newbie-8/help-to-replace-a-pattern-with-sed-or-awk-914838/)

rramesh1 11-21-2011 11:35 PM

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

jimtony 11-22-2011 12:02 AM

Use the following command:
Quote:

sed 's/testreport.data/\/home\/test\/run\/testreport.data/'

grail 11-22-2011 12:06 AM

Or to make it a little easier to read:
Code:

sed -r 's@(testreport.data)@/home/test/run/\1@' file


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