Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with sed.

Status
Not open for further replies.

bigscouse

MIS
Oct 6, 1998
420
0
0
GB
I am trying to use in sed in a bourne script. Running on SVR4.<br>
My code looks like this: -<br>
<br>
for AA in `cat migration.list` <br>
do <br>
cat $PROCDIR/$AA.in ¦ sed -e 's/ $AA/ $AA_tmp/g'<br>
-e 's/ii_data/slave_data/g' &gt; $AA.in1 <br>
done<br>
<br>
When I run it I get this message <br>
&quot;UX:sh (./migration.sh): ERROR: -e: Not found&quot; <p>Ged Jones<br><a href=mailto:gedejones@hotmail.com>gedejones@hotmail.com</a><br><a href= > </a><br>
 
I think you'll need to pipe the output from the sed into another sed. eg:<br>
<br>
for AA in `cat migration.list` <br>
do<br>
cat $PROCDIR/$AA.in ¦ sed -e 's/ $AA/ $AA_tmp/g' ¦ sed -e 's/ii_data/slave_data/g' &gt; $AA.in1 <br>
done<br>
<br>
AFAIK, sed doesn't take multiple '-e' options, and it's interpreting yours as being the name of a file it's going to try and parse...<br>
<br>
Hope this helps.
 
This is weird, I did get it work first time I tried, but now it is not working at all. It seems as if sed will not read the variable. If I run with sh -x then the screen diplays the variables as having been interpreted but no action is taken on the file. If I use the variable in string2 only, then the replacement works.However sed will not interpret the variale in string 1. Same thing happens with ed. <p>Ged Jones<br><a href=mailto:gedejones@hotmail.com>gedejones@hotmail.com</a><br><a href= > </a><br>
 
It's probably a regexp thing. Further contemplation reminds me that '$' is the end-of-line indicator in regexp, so sed is probably looking for _tmp at the end of a line, or something. Must have needed more coffee the day I replied :)<br>
<br>
Try changing:<br>
cat $PROCDIR/$AA.in ¦ sed -e 's/ $AA/ $AA_tmp/g' ¦ sed -e 's/ii_data/slave_data/g' &gt; $AA.in1<br>
<br>
to be<br>
<br>
cat $PROCDIR/$AA.in ¦ eval sed -e 's/${AA}/${AA}_tmp/g' ¦ sed -e 's/ii_data/slave_data/g' &gt; $AA.in1<br>
<br>
The eval will replace the $AA references with the actual value of $AA before running the 'sed' command.<br>
<br>
That should work a little better :)<br>
<br>
(Note: The {} brackets are necessary. Without them, eval will interpret $AA_tmp as being $AA_tmp, not as $AA with _tmp appended to whatever $AA is set to. So, without the brackets, assuming $AA contain ABCD, you'd end up with &quot;sed -e 's/ABCD//g'&quot;. Definitely *not* the desired result. :)<br>
<br>
Hope this helps a bit more. :)
 
Another thing that may work is to just use double quotes &quot; instead of apostrophes '. Apostrophes keep the shell from intrerpolating variables, but double quotes says to go ahead and interpolate the variables.<br>
<br>
eval works because it accepts the string as indicated by the apostrophe as a unit, then hands that unit off to a subshell to run. At that point there aren't any apostrophes, so the variable interpolates.
 
Just in case anybody gets a similar problem:<br>
This was a classic case of the old cut and paste syndrome. When I pasted the working text into another script it also placed spaces after the end marker so sed did not recognise the marker. <p>Ged Jones<br><a href=mailto:gedejones@hotmail.com>gedejones@hotmail.com</a><br><a href= > </a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top