![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | 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 here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to search and replace text in same file | Vrgurav | Shell Programming and Scripting | 1 | 04-25-2008 03:20 AM |
| input text into file | cannonfodder | Shell Programming and Scripting | 1 | 12-15-2007 07:37 AM |
| script - replace text in file | frustrated1 | Shell Programming and Scripting | 4 | 01-01-2006 11:10 PM |
| How to input username on text file into finger command on shell script | Micz | Shell Programming and Scripting | 3 | 11-07-2005 11:38 PM |
| Replace line of text in a file | colinchase | UNIX for Dummies Questions & Answers | 3 | 10-04-2001 06:54 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
I wish to replace values of specific parameters in an input file for batch runs of a java code. It's essentially a nested for-loop sorta like this:
valuearray1 contains values for param1 valuearray2 contains values for param2 for (all values in valuearray1) go into specific position in "input.txt" (marked by say character pos1) and replace param1 with current value from valuearray1 for (all values in valuearray2) go into specific position in "input.txt" (marked by say character pos2) and replace param2 with current value from valuearray2 run the simulation code get next value from valuearray2 get next value from valuearray1DONE! I'm new to scripting so any help from the experts would be deeply appreciated! -Sam |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Where do the arrays get their data from? Is it in a file or do you store it in the script?
What does "marked by character x" mean? Like find a line with the specified character at the beginning and only substitute on that particular line? Or all lines following that line? Or all lines with that marking? Does input.txt need to change on every iteration or can the java program read it on standard input? I would suggest to keep a static file and run each java program on a temporary copy. Code:
#!/bin/sh
valuearray1="foo bar baz"
valuearray2="ick y poo"
for v1 in $valuearray1; do
for v2 in $valuearray2; do
sed -e "/^pos1/s/param1/$v1/" -e "/^pos2/s/param2/$v2/" input.txt >/tmp/input.txt
java suction /tmp/input.txt
done
done
|
|
#3
|
|||
|
|||
|
You've got it, the code works beautifully after some changes here and there. Thx!
|
|||
| Google The UNIX and Linux Forums |