[NTLUG:Discuss] change words on every line in a file

Rusty Haddock rusty at fe2o3.lonestar.org
Sat Mar 24 15:08:11 CDT 2012


Fred James wrote:
    > #!/bin/sh
    > v='9899'
    > cat file | while read s1 s2
    > do
    > if [ "$s2" != "$v" ]; then
    >     echo $s1 '--' $s2
    >    cat  "$s1" ' ' "$IPADDR" >> file
    >    sed -i '/$s2/ d' file

If you want shell variable substitution to occur, the sed command '/$s2/ d'
will need to be in double quotes ("), not single, otherwise the dollar sign
is passed to sed's regular expression parser.

Oh, and where is $IPADDR getting defined??

	-Rusty-
-- 
   _____                Rusty Haddock  <=>  AE5AE
|\/   o \   o             Way out yonder in the
|   (  -<  O o      Van Alstyne (TX) Metropolitan Area
|/\__V__/       Math illiteracy affects 7 out of 5 people!



More information about the Discuss mailing list