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
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
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:
Summary: Hi I am using sed in a shell script. I am having problems in using parameters in sed for search and replace. TEST=`grep "'/" source | head -1` sed s/$TEST/string1/g source.txt > target.txt This doesn...
Summary: Hi, I'm trying to do the following :- rsh remote sed "s/ //g" remote_file >> local_file but I get :- sed: command garbled: s/ Now I know that sed "s/ //g" local_in_file >> local_out_file works ok (it...
Summary: Is it possible to pass a Unix environment variable to sed? The example script I have included shows what I am trying to do and the header explains why. I am running this script on Solaris KSh. #######...