![]() |
Bash scripting
Hi
I am tryinf to something relatively simple but seem unable to get this script working. I simply want to replace the number associated with a certain work. I am using sed. However when I incorporate the working sed command into my script it does not work any longer. #!/bin/sh for i in `seq 0 9` do x=24 y=1000 Result=`expr $i + $y` c="LIPID "$i d="LIPID "$Result echo $c echo $d e="'s/"$c"/"$d"/g' MCdemo.txt" f="sed "$e $f done This is the error: sed: -e expression #1, char 1: unknown command: `'' Could someone please point out what is going wrong... |
I think you should get rid of some of the variables and quotes. Instead of "$f", why don't you write something like
Code:
sed "s/$c/$d/g" MCdemo.txt |
OK thanks..that doesnt error now, but I find that I'm not replacing the text as desired!
The file that I am looking at looks like: XWIDTH 25 YWIDTH 25 ZWIDTH 9 LIPID 0 SPECIES 0 BEAD 0 7.46896 14.12 1.78805 SIZE 1.3 XREF 0 YREF 0 ZREF 0 BEAD 1 7.54717 13.4669 2.44324 SIZE 0.45 Its not pikcing out the Lipid 0 - any idea? |
It does. In the first loop, "LIPID 0" is replaced with "LIPID 1000".
|
I am not sure what is going on with the scheme as it loops around and when I look at the output lipid 0 is still there. Should I be outputting to a different file? I need to loop around 100 times.
|
I decreased the number of loops to 2, to make the output a little shorter for the post. But then, it will look as follows, and that's precisely what it's supposed to do. If you want something different, you'll have to say so. I also added a line to indicate where the loop begins:
Code:
-- loop 0 |
| All times are GMT -5. The time now is 07:56 AM. |