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

Ralph Green sirable at gmail.com
Sat Mar 24 13:37:34 CDT 2012


Howdy,
  I would probably write a short Python program to do this.  If the
examples you have been given, then just use them.  If this is a
program you will be using often of for a long time, or you expect the
algorithm will need tweaking over time, then Python's readability is
an advantage to me.Ralph


On 3/23/12, Fred James <fredjame at fredjame.cnc.net> wrote:
> 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
>
>
> _______________________________________________
> http://www.ntlug.org/mailman/listinfo/discuss
>



More information about the Discuss mailing list