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

Fred James fredjame at fredjame.cnc.net
Fri Mar 23 19:03:00 CDT 2012


o k wrote:
>
>
> All is there any have a good suggestion on change words on every line in a file. ex:original: dog     1234cat     1234mouse  1234houesr 1234 after changed dog 9899cat 9899mouse 9899house 9899 I have this, but seems to not woking: #!/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
> fi
> done
> exit 0 thank for your help.   		 	   		  
>   
Context is all important ... the read (within the while statement) 
suggest that there are 2 and only 2 values per line (i.e., each 
line/record contains two space separated words ...
    first:  is that true?
    second: v='9899', s2=? (dog, cat, 1234dog, 1234cat, etc)? ... all of 
these will be unequal to 9899 ... is that what you want?
... that all my commends/questions for the moment
Regards
Fred James




More information about the Discuss mailing list