[NTLUG:Discuss] change words on every line in a file
o k
aaasssxxx at hotmail.com
Mon Mar 26 09:54:23 CDT 2012
All
Sorry I repost for clarify Is there any have a good suggestion on change words on every line in a file, line by line.
ex:
original:
dog 1234cat 1234mouse 1234horse 1234
after changed: dog 9899cat 9899mouse 9899house 9899
I have this, but seems to not working:
#!/bin/shv='9899'cat file | while read s1 s2doif [ "$s2" != "$v" ]; then echo $s1 '--' $s2 cat "$s1" ' ' "$v" >> file //add new line to file? sed -i '/$s2/ d' file //delete a line contain value $2?fidoneexit 0
thank for your help.
> From: aaasssxxx at hotmail.com
> To: discuss at ntlug.org
> Date: Mon, 26 Mar 2012 14:40:42 +0000
> Subject: Re: [NTLUG:Discuss] change words on every line in a file
>
>
> 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
>
> _______________________________________________
> http://www.ntlug.org/mailman/listinfo/discuss
More information about the Discuss
mailing list