change all "abc" to "123"

change all "abc" to "123"

Post by Zhihui Zhan » Sun, 13 Jan 2002 03:21:52



I have a lot of files that contain string "abc" that I want to change
them to "123".  I try to use sed like this:

#!/bin/sh
for i in `find . -type f -print`
do
        sed s/abc/123 < $i >$i.temp
done

Please help me with the grammer of sed.   Thanks.

-Zhihui
--

 
 
 

change all "abc" to "123"

Post by ted » Sun, 13 Jan 2002 04:12:22



>         sed s/abc/123 < $i >$i.temp

a few remarks :
        - 's/abc/123/g' will replace multiple occurences of abc
        - don't put < before the input file
Hope this helps

 
 
 

change all "abc" to "123"

Post by Bill Marcu » Sun, 13 Jan 2002 04:06:32



>I have a lot of files that contain string "abc" that I want to change
>them to "123".  I try to use sed like this:

>#!/bin/sh
>for i in `find . -type f -print`
>do
>        sed s/abc/123 < $i >$i.temp

sed s/abc/123/ < "$i" >"$i.temp"
this will change the first "abc" on each line ("abcdabc" to "123dabc")
To change "abcdabc" to "123d123"
sed s/abc/123/g <$i >$i.temp

mv "$i.temp" "$i"
(use quotes in case some file names contain spaces)

Quote:>done

>Please help me with the grammer of sed.   Thanks.

>-Zhihui
>--

 
 
 

change all "abc" to "123"

Post by Triten » Sun, 13 Jan 2002 04:53:18


Zhihui Zhang says:

Quote:

> I have a lot of files that contain string "abc" that I want to change
> them to "123".  I try to use sed like this:

> #!/bin/sh
> for i in `find . -type f -print`
> do
>         sed s/abc/123 < $i >$i.temp
> done

sed s/abc/123/ $i > $i.temp

should work...

--
first name: Jacek  last name: Pospycha3a           .-photo---.
nick: triteno      web: http://tri10o.republika.pl | can't   |

                                                   |_DISPLAY_|

 
 
 

change all "abc" to "123"

Post by Barry Margoli » Sun, 13 Jan 2002 07:03:35




Quote:

>I have a lot of files that contain string "abc" that I want to change
>them to "123".  I try to use sed like this:

>#!/bin/sh
>for i in `find . -type f -print`
>do
>        sed s/abc/123 < $i >$i.temp
>done

>Please help me with the grammer of sed.   Thanks.

RTFM.  "man sed" shows:

  s/regular expression/replacement/flags

You're missing the "/" that separates the replacement from the flags.

--

Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

 
 
 

change all "abc" to "123"

Post by JBruno71 » Mon, 14 Jan 2002 00:17:06


If I remember correctly the correct syntax is:  sed s/abc/123/g

The 'g' tells it to do it for the whole file, otherwisr it would only do it on
the current line.

Josh

 
 
 

change all "abc" to "123"

Post by Torgny Lyo » Mon, 14 Jan 2002 04:48:06



> If I remember correctly the correct syntax is:  sed s/abc/123/g

> The 'g' tells it to do it for the whole file, otherwisr it would only do it on
> the current line.

> Josh

No, the g flag is used to replace all instances of "abc" on the current line to
"123", no just the first one. sed applies the command to every line anyway if
there is no address specified, as in this case.

Torgny Lyon