Shell Script to new file referring other files -
can please in writing shell script below requirement.
i have csv file shown below in comma separated format
a,b,c d,e,f
there file in values written mentioned below:-
ramesh suresh
with of above 2 files need construct new file.
<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>
try this;
#!/bin/bash echo "<root>" while read csvline; echo $csvline | awk -f ',' '{print "<env name=\""$1 "\" domain=\"" $2"\">"}' csvcol3=$(echo $csvline |awk -f ',' '{print $3}') while read secondfileline; 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>"
Comments
Post a Comment