The UNIX and Linux Forums  

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

More UNIX and Linux Forum Topics You Might Find Helpful
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 06:37 AM
script - replace text in file frustrated1 Shell Programming and Scripting 4 01-01-2006 10:10 PM
How to input username on text file into finger command on shell script Micz Shell Programming and Scripting 3 11-07-2005 10:38 PM
Replace line of text in a file colinchase UNIX for Dummies Questions & Answers 3 10-04-2001 06:54 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-23-2008
Registered User
 

Join Date: Apr 2008
Posts: 2
Thumbs down Replace text in input file

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 valuearray1
DONE!

I'm new to scripting so any help from the experts would be deeply appreciated!

-Sam
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 04-24-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,111
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
Reply With Quote
  #3 (permalink)  
Old 04-25-2008
Registered User
 

Join Date: Apr 2008
Posts: 2
You've got it, the code works beautifully after some changes here and there. Thx!
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 02:39 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0