![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 |
|
||||
|
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 Code:
:/tmp # cat build.xml createConfig machine="serverxx1" createConfig machine="serverxx2" createConfig machine="serverxx3" Nir |
|
||||
|
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 ?? |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|