The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Problem in For Loop The Observer Shell Programming and Scripting 2 05-28-2008 02:43 AM
for loop problem namishtiwari Shell Programming and Scripting 5 01-25-2008 12:58 PM
loop problem maskot Shell Programming and Scripting 1 05-25-2007 04:10 AM
loop Problem dhananjaysk Shell Programming and Scripting 3 03-31-2006 01:05 PM
problem with while loop mridula High Level Programming 1 12-11-2005 11:44 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-26-2006
chiru_h chiru_h is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 72
Problem with for loop/sed ?

I have a hostnames file which has:
$ cat hostnames.txt
serverxx1
serverxx2
serverxx3

My script:
#!/bin/sh
fileA=build.xml
for i in ./hostnames.txt ; do
sed 's/createConfig machine="Machine"/createConfig machine=" '$i' "/g' "$fileA" > ./tmpfile
done

FileA has:
createConfig machine="Machine"

Output should have FileA:
createConfig machine="serverxx1"
createConfig machine="serverxx2"
createConfig machine="serverxx3"

But I am getting error as
sed: -e expression #1, char 58: Unknown option to `s'

If I change '$i' to just $i , it's replacing Machine with $i not it's value.

Can somebody please help me - if I am using the sed/for properly?

Thankyou
chiru_h
  #2 (permalink)  
Old 08-27-2006
nir_s nir_s is offline
Registered User
  
 

Join Date: Jun 2004
Posts: 148
To achieve your target,I recommend you to generate dynamically the file build.xml instead of using replacing parameters:

Code:
#!/bin/sh

fileA=build.xml
if [[ -f $fileA ]] ; then
  \rm $fileA
fi

for line in `cat hostnames.txt`
do
  echo "createConfig machine=\"$line\"" >> $fileA
done
After running this script ,build.xml is created and its content is:

Code:
:/tmp # cat build.xml 
createConfig machine="serverxx1"
createConfig machine="serverxx2"
createConfig machine="serverxx3"
Regards,
Nir
  #3 (permalink)  
Old 08-27-2006
chiru_h chiru_h is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 72
Now the build.xml only has these values. My original build.xml has other stuff above and below it.
What I need is it has to replace the line
createConfig machine="Machine"
with
createConfig machine="serverxx1"
createConfig machine="serverxx2"
createConfig machine="serverxx3"

any ideas
??
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:21 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0