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

o k aaasssxxx at hotmail.com
Mon Mar 26 09:40:42 CDT 2012


Fred and all,
Sorry for confusion, the context (file) will be:
These is only 2 columns per line. space between 2 values can be change to desired space. (one space, 2 spaces... or tab)the first column is all different animal names.the second will be all same string. and I want to change them one line by one line through loop.$s2 value (was 1234)  should be replaced to $v (9899) -> after changed, second: v='9899', s2='9899'
Still looking for help.  Thanks.


> Date: Fri, 23 Mar 2012 19:03:00 -0500
> From: fredjame at fredjame.cnc.net
> To: discuss at ntlug.org
> Subject: Re: [NTLUG:Discuss] change words on every line in a file
> 
> 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