LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-29-2006, 12:17 PM   #1
disruptive
Member
 
Registered: Dec 2005
Posts: 76

Rep: Reputation: 15
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...
 
Old 06-29-2006, 12:44 PM   #2
spirit receiver
Member
 
Registered: May 2006
Location: Frankfurt, Germany
Distribution: SUSE 10.2
Posts: 424

Rep: Reputation: 33
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
?
 
Old 06-29-2006, 01:08 PM   #3
disruptive
Member
 
Registered: Dec 2005
Posts: 76

Original Poster
Rep: Reputation: 15
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?
 
Old 06-29-2006, 01:50 PM   #4
spirit receiver
Member
 
Registered: May 2006
Location: Frankfurt, Germany
Distribution: SUSE 10.2
Posts: 424

Rep: Reputation: 33
It does. In the first loop, "LIPID 0" is replaced with "LIPID 1000".
 
Old 06-29-2006, 03:01 PM   #5
disruptive
Member
 
Registered: Dec 2005
Posts: 76

Original Poster
Rep: Reputation: 15
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.
 
Old 06-29-2006, 03:49 PM   #6
spirit receiver
Member
 
Registered: May 2006
Location: Frankfurt, Germany
Distribution: SUSE 10.2
Posts: 424

Rep: Reputation: 33
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.

Last edited by spirit receiver; 06-29-2006 at 04:03 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash scripting.. kurrupt Programming 3 09-21-2005 12:07 AM
Bash Scripting Help Aioth Linux - Newbie 8 09-21-2004 11:21 AM
need help with bash scripting rich2oo1 Programming 2 12-17-2003 12:50 PM
Bash scripting SWAT Linux - Newbie 2 11-11-2003 03:21 AM
Bash scripting NSKL Linux - General 2 06-08-2002 12:10 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:43 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration