Computing.Net > Forums > Unix > parameters to sed doesnt work

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.

parameters to sed doesnt work

Reply to Message Icon

Name: arvindkantheri
Date: July 5, 2006 at 19:47:49 Pacific
OS: UNIX
CPU/Ram: 512Mb
Product: HP
Comment:

hello all,

I have a to find and replace a strings in a file, for which I have a findstring.txt, which contains all strings to be found in each line and replacestring.txt, which contains all strings to be replaced in each line. I am using these two files on a targetfile.txt to find and replace using sed.
findstring.txt and replacestring.txt may contain, strings with special characters such as '.'.
When I run below piece of code, I dont see find and replace is working fine. I am sure, there is some pbm with sed syntax I used. Plz help me.

#!/bin/sh
files=`ls *.txt`

exec 5< test/findthis.txt
exec 6< test/replacethis.txt
until [ $done ]
do
read <&5 myfindline
read <&6 myreplaceline
if [ $? != 0 ]
then
done=1
continue
fi
for myfile in $files
do
sed -e "s/$myfindline/$myreplaceline/g" $myfile > targetfile
done
done


Thanks
Arvind K



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: July 6, 2006 at 07:34:26 Pacific
Reply:

You are attempting to implement a replacement in sed. Arnold Robbins implemented a sed version in his "Sed & Awk" book published by O'Reilly. He called the command 'gres' - global regular expression substitution. See it here:

http://www.sm.luth.se/~alapaa/file_fetch/unixcdbookshelf/sedawk/ch03_02.htm

See the side-bar in section 3.2.11


0
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: parameters to sed doesnt work

parameters in sed www.computing.net/answers/unix/parameters-in-sed/6942.html

Problems using 'sed' through 'rsh' www.computing.net/answers/unix/problems-using-sed-through-rsh/3571.html

Pass environment variables to sed www.computing.net/answers/unix/pass-environment-variables-to-sed/7387.html