我有一个文件abc.csv,如下所示; -
sn,test,control
1,file1,file2
2,file3,file4
我有另一个配置文件text.cfg,如下所示: -
model.input1 = /usr/bin/file1
model.input2 = /usr/bin/file2
现在我想用file替换file1和file2 分别是file3和file4 file5和file6等等,直到abc.csv文件耗尽
我对这个问题的尝试是: -
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
输出应该是新的配置文件,如下所示: -
这是test1.cfg
:
model.input1 = /usr/bin/file1
model.input2 = /usr/bin/file2
然后第二个文件应为test2.cfg
model.input1 = /usr/bin/file3
model.input2 = /usr/bin/file4
依旧......
答案 0 :(得分:0)
awk -F, 'NR>1{i = 0; while(++i < NF){print "model.input"i" = /usr/bin/"$(i+1) >> "test"$1".cfg"} }' File
输出:
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
希望这有帮助。