Changing the nth parameter in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Changing the nth parameter in a file
# 1  
Old 09-29-2014
Changing the nth parameter in a file

Hello,

I use a program using an input stream of parameters:
.
Code:
/my_prog.out <parameters.txt

The parameters.txt file has the following structure:

Code:
name
date
number1
number2
system

now imagine i would like to execute several times (>200) this program, but with different sets of number1 and number2. Is there a way to automatize this by making a shell to change these two very parameters into other numbers? I have no idea how to do that. Could anyone help? Smilie

for example it would be a script doing something like this:

Code:
for number1=1 to 100
for number 2 = 3 to 7
change myparameters.txt in these two specific field <- dunno how to do that
./my_prog.out <parameters.txt &

many thanks!

Moderator's Comments:
Mod Comment edit by bakunin: please use CODE-tags as required by the forum rules. Thank you.

Last edited by bakunin; 09-29-2014 at 07:04 PM..
# 2  
Old 09-29-2014
Direct the input stream to sed. In sed there are provisions to only change the nth line, for instance:

Code:
sed '7 s/X/y/g'

will change all "X"es to "y"s only on the seventh line. Try it out.

I hope this helps.

bakunin
# 3  
Old 09-29-2014
You could also use a here-doc in this fashion:

Code:
for number1 in $(seq 1 100)
do
    for number2 in $(seq 3 7)
    do
        ./my_prog.out <<EOF
name
date
$number1
$number2
system
EOF
    done
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Help changing date format in the nth field

Hi, I have two (2) things that I want to do. First is to change the date format that is in the nth field from MM/DD/YY to YY/MM/DD. Preferably, I wish I know how to make it a 4-digit year but I don't. Problem is I can only assume it is a 20 century Second is somehow know how to figure out... (1 Reply)
Discussion started by: newbie_01
1 Replies

2. Shell Programming and Scripting

Replace a value of Nth field of nth row

Using Awk, how can I achieve the following? I have set of record numbers, for which, I have to replace the nth field with some values, say spaces. Eg: Set of Records : 4,9,10,55,89,etc I have to change the 8th field of all the above set of records to spaces (10 spaces). Its a delimited... (1 Reply)
Discussion started by: deepakwins
1 Replies

3. Shell Programming and Scripting

Parameter file with changing date

Hi, I have a trigger file which looks like this abcdefgh_YYYYMMDD.trg The YYYYMMDD is the year, month and the date. So for example today the trigger file would be abcdefgh_20130703.trg similarly tomorrow it would be abcdefgh_20130704.trg I need to write a script to check if the trigger file... (2 Replies)
Discussion started by: halfafringe
2 Replies

4. Shell Programming and Scripting

awk - printing nth field based on parameter

I have a need to print nth field based on the parameter passed. Suppose I have 3 fields in a file, passing 1 to the function should print 1st field and so on. I have attempted below function but this throws an error due to incorrect awk syntax. function calcmaxlen { FIELDMAXLEN=0 ... (5 Replies)
Discussion started by: krishmaths
5 Replies

5. Shell Programming and Scripting

How to get the parameter value from the parameter file in perl?

hi all, i have a parameter file of following format, i want a method which can get the value of specific parameter. parameter file format: <Parameter Name="FileLocationWindows"> <Description> The directory location of the logger file. ... (1 Reply)
Discussion started by: laxmikant.hcl
1 Replies

6. Shell Programming and Scripting

Retreiving multiple files by changing a parameter with one program

Hi all, I am using following command: perl program.pl input.txt output.txt CUTOFF 3 > groups_3.txt containing program.pl, two files (input.txt, output.txt) and getting output in groups_3.txt: But, I wish to have 30 files corresponding to each CUTOFF ranging from 0 to 30 using the same... (1 Reply)
Discussion started by: bioinfo
1 Replies

7. Shell Programming and Scripting

Calculating average for every Nth line in the Nth column

Is there an awk script that can easily perform the following operation? I have a data file that is in the format of 1944-12,5.6 1945-01,9.8 1945-02,6.7 1945-03,9.3 1945-04,5.9 1945-05,0.7 1945-06,0.0 1945-07,0.0 1945-08,0.0 1945-09,0.0 1945-10,0.2 1945-11,10.5 1945-12,22.3... (3 Replies)
Discussion started by: ncwxpanther
3 Replies

8. Shell Programming and Scripting

Using AWK to find top Nth values in Nth column

I have an awk script to find the maximum value of the 2nd column of a 2 column datafile, but I need to find the top 5 maximum values of the 2nd column. Here is the script that works for the maximum value. awk 'BEGIN { subjectmax=$1 ; max=0} $2 >= max {subjectmax=$1 ; max=$2} END {print... (3 Replies)
Discussion started by: ncwxpanther
3 Replies

9. UNIX for Dummies Questions & Answers

Repeating a column but changing one parameter

Does anyone know how I can create a file like this: blue 0 red 0 yellow 0 green 0 orange 0 blue 2 red 2 yellow 2 green 2 orange 2 blue 4 red 4 yellow 4 green 4 orange 4 blue 6 red 6 (5 Replies)
Discussion started by: cosmologist
5 Replies

10. IP Networking

Changing network parameter in Existing OS image

Hi , Can some one tell me , is there a way to change the existing network parameter in existing OS image , or do i have to create a new image to have new network parameters . (0 Replies)
Discussion started by: thana
0 Replies
Login or Register to Ask a Question