1833338 Members
2591 Online
110051 Solutions
New Discussion

sed

 
SOLVED
Go to solution
System Dude_1
Frequent Advisor

sed

Dear Friend,

How could I pass an argument to a sed ?

INS=`cat failed.log8|awk '{print $1}'`
sed -e 's/$/ $INS/g' failed.log3 > failed.log4
Performance Issue on HP-UX 10.20
4 REPLIES 4
Paul Thomson_2
Super Advisor

Re: sed

Only just learning sed my self.

Have attached some examples someone gave me..

Hope this helps.

Argh ye land lovers !
Steve Steel
Honored Contributor

Re: sed

Hi


try

sed -e "s/$/ $INS/g" failed.log3 > failed.log4


Steve Steel


See

http://www.unet.univie.ac.at/aix/cmds/aixcmds5/sed.htm

copy an existing file (oldfile) to a new file (newfile) and replace all occurrences of the testpattern text string with the contents of the $REPL shell variable, enter:
cat oldfile | sed -e "s/testpattern/$REPL/g" > newfile
If you want truly to understand something, try to change it. (Kurt Lewin)
Systeemingenieurs Infoc
Valued Contributor
Solution

Re: sed

You can also do it with ed (you don't need a temp-file with it) :

replace_string()
{
fname="$1"
from="$2"
to="$3"

ed -s $fname <1,$ s/$from/$to/g
w $fname
q
EOF
}
A Life ? Cool ! Where can I download one of those from ?
H.Merijn Brand (procura
Honored Contributor

Re: sed

Though Steve's anwer is correct, he doesn't mention why /your/ answer is wrong: you are using single quotes, which makes $INS not expanding.

The explanation can be found in the man page of the shell you are using

Double quotes also interpolate backticks:

l1:/u/usr/merijn/.elvislib 128 > echo "I'm at `pwd` now"
I'm at /u/usr/merijn/.elvislib now
l1:/u/usr/merijn/.elvislib 129 >

And your command can be a single pass:

sed -e 's/$/ '`awk '{print $1}' < failed.log8`'/' failed.log3 >failed.log4
Enjoy, Have FUN! H.Merijn