0
votes

I have a file abc.csv which is as follows;-

sn,test,control
1,file1,file2
2,file3,file4

i have another configuration file text.cfg as follows:-

model.input1 = /usr/bin/file1
model.input2 = /usr/bin/file2

now i want to replace the file1 and file2 with file3 and file4 respectively and then file5 and file6 and so on,, till the abc.csv file is exhausted

my attempt for the problem is :-

IFS =","

while read NUM TEST CONTROL


X=""
Y=""

do
    echo "Serial Number :$NUM"
    echo "Test File :$TEST"
    echo "Control File:$CONTROL"

    sed -i -e 's/$A/$B/g' text.cfg

    X = $TEST
    Y = $CONTROL

done < abc.csv

the ouput should be new config files as follows:-

this is the test1.cfg:

model.input1 = /usr/bin/file1
model.input2 = /usr/bin/file2

then the second file should be test2.cfg

model.input1 = /usr/bin/file3
model.input2 = /usr/bin/file4

and so on..

1
It would be useful if you also showed us the exact output you expect from the input you've shown. Please edit your question to do so. - Tom Fenech
I don't understand your requirements. - 5gon12eder
I need to change the test.cfg file by looping through every line in the abc.csv file and changing the file names as given in the abc.csv file line by line - ch1nmay
Things like IFS ="," are wrong, you should paste your script in www.shellcheck.net to clear these errors and then focus on the logic. - fedorqui 'SO stop harming'

1 Answers

0
votes
awk -F, 'NR>1{i = 0; while(++i < NF){print "model.input"i" = /usr/bin/"$(i+1) >> "test"$1".cfg"} }' File

Output:

AMD$ cat test1.cfg
model.input1 = /usr/bin/file1
model.input2 = /usr/bin/file2
AMD$ cat test2.cfg
model.input1 = /usr/bin/file3
model.input2 = /usr/bin/file4

Hope this helps.