LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Bash scripting (http://www.linuxquestions.org/questions/programming-9/bash-scripting-459497/)

disruptive 06-29-2006 01:17 PM

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...

spirit receiver 06-29-2006 01:44 PM

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
?

disruptive 06-29-2006 02:08 PM

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?

spirit receiver 06-29-2006 02:50 PM

It does. In the first loop, "LIPID 0" is replaced with "LIPID 1000".

disruptive 06-29-2006 04:01 PM

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.

spirit receiver 06-29-2006 04:49 PM

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
LIPID 0
LIPID 1000
XWIDTH 25
YWIDTH 25
ZWIDTH 9
LIPID 1000
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
-- loop 1
LIPID 1
LIPID 1001
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

As you see, "LIPID 0" has been replaced with "LIPID 1000" in the first loop.


All times are GMT -5. The time now is 06:47 PM.