Computing.Net > Forums > Unix > Sed in While loop not working

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Sed in While loop not working

Reply to Message Icon

Name: Brucee
Date: April 22, 2004 at 03:26:10 Pacific
OS: Windows 2000
CPU/Ram: Intel Celeron 2 GHz / 512
Comment:


Hi ,
I have a folder containing abt 50 files each of which has the tag <xyz>abcd</xyz>
I want to replace the text between the tags - abcd (it need not be abcd , can be 50 diff strings ) in this case with the file names of these files or anything unique ..
I am trying
ls REG* | while read i
do
sed s/\<xyz\>*\<\/xyz\>/\<xyz\>i\<\/xyz\>/ $i
done

but getting sed:command garbled ... Pls suggest ..

Cheers,
Nil.




Sponsored Link
Ads by Google

Response Number 1
Name: Wolfbone
Date: April 22, 2004 at 04:14:41 Pacific
Reply:

No single or double quotes surrounding the sed expression? Depends on your shell but try:

sed "s/<xyz>.*<\/xyz>/<xyz>$i<\/xyz>/" $i

(You shouldn't need to escape the '<' or '>' signs and you missed out the '.' match any).


0

Response Number 2
Name: Brucee
Date: April 22, 2004 at 04:40:19 Pacific
Reply:

Hi,
Thnx ya, the thing worked perfect. Me didn't have idea abt not escaping the '<' and '>' chars , missing the '.' was a oversight though .

Cheers,
Nil..


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Sed in While loop not working

Using while loop to read a file www.computing.net/answers/unix/using-while-loop-to-read-a-file/7092.html

Encryption Code Not Working www.computing.net/answers/unix/encryption-code-not-working/5974.html

AWK in a while loop www.computing.net/answers/unix/awk-in-a-while-loop/6669.html