2016-07-28 18 views
0

任何人都可以請求幫助編寫shell腳本以滿足以下要求。Shell腳本到新文件引用其他文件

我有一個CSV文件作爲逗號分隔的格式如下所示

A,B,C 
D,E,F 

存在其中值被寫入如下所述另一個文件: -

Ramesh 
Suresh 

隨着上述的幫助我需要構建新文件的兩個文件。

<root> 
<env name="A" domain="B"> 
    <component name="Ramesh"> 
     <machine name="C">Ramesh</machine> 
    </component> 
    <component name="Suresh"> 
     <machine name="C">Suresh</machine> 
    </component> 
</env> 
<env name="D" domain="E"> 
    <component name="Ramesh"> 
     <machine name="F">Ramesh</machine> 
    </component> 
    <component name="Suresh"> 
     <machine name="F">Suresh</machine> 
    </component> 
</env> 
</root> 
+1

包括你試過的東西。 – Fazlin

回答

0

試試這個;

#!/bin/bash 
echo "<root>" 
while read csvLine; do 
    echo $csvLine | awk -F ',' '{print "<env name=\""$1 "\" domain=\"" $2"\">"}' 
    csvcol3=$(echo $csvLine |awk -F ',' '{print $3}') 
     while read secondFileLine; do 
     echo -e '\t<component name="'$secondFileLine'">' 
     echo -e '\t\t<machine name="'$csvcol3'">'$secondFileLine'</machine>' 
     echo -e '\t</component>' 
     done < SecondFile.txt 
    echo '</env>' 
done < file.CSV 
echo "</root>" 
+0

Thnx這麼多... – user6376225

+0

@ user6376225接受答案並請upvote請 –