0

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

4
  • 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. Commented Jan 20, 2016 at 10:01
  • I don't understand your requirements. Commented Jan 20, 2016 at 10:05
  • 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 Commented Jan 20, 2016 at 10:07
  • Things like IFS ="," are wrong, you should paste your script in www.shellcheck.net to clear these errors and then focus on the logic. Commented Jan 20, 2016 at 10:21

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! This is what i needed!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.