[NTLUG:Discuss] Discuss Digest, Vol 111, Issue 2
o k
aaasssxxx at hotmail.com
Mon Mar 26 10:00:31 CDT 2012
Thank, I am looking for replace the value line by line after comparison (
"$s2" != "$v" ) .
> Date: Sat, 24 Mar 2012 22:20:48 -0700
> From: oakleeman at yahoo.com
> To: discuss at ntlug.org
> Subject: Re: [NTLUG:Discuss] Discuss Digest, Vol 111, Issue 2
>
>
> >
> > 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.
> >
> >
> >
> >
>
> If you are simply wanting to replace "1234" with "9899" then I think the following should work:
>
> cp /path/to/filename /tmp/filename.tmp
> sed s/"1234"/"9899"/g < /tmp/filename.tmp> /path/to/filename
> rm -rf /tmp/filename.tmp
>
> if you are wanting to write it into a script that you can pass two variables to then I think that it will look like this:
>
> cp /path/to/filename /tmp/filename.tmp
> sed s/"$1"/"$2"/g < /tmp/filename.tmp> /path/to/filename
> rm -rf /tmp/filename.tmp
>
>
> _______________________________________________
> http://www.ntlug.org/mailman/listinfo/discuss
More information about the Discuss
mailing list