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
How to search and replace text in same file Vrgurav Shell Programming and Scripting 1 04-25-2008 06:20 AM
input text into file cannonfodder Shell Programming and Scripting 1 12-15-2007 10:37 AM
script - replace text in file frustrated1 Shell Programming and Scripting 4 01-02-2006 02:10 AM
How to input username on text file into finger command on shell script Micz Shell Programming and Scripting 3 11-08-2005 02:38 AM
Replace line of text in a file colinchase UNIX for Dummies Questions & Answers 3 10-04-2001 09:54 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-23-2008
daphantomica daphantomica is offline
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
  #2 (permalink)  
Old 04-24-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
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 (permalink)  
Old 04-25-2008
daphantomica daphantomica is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 2
You've got it, the code works beautifully after some changes here and there. Thx!
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 09:01 PM.


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