I am trying to parse multiple awk variables into a for loop. I have a document that consists of multiple fields separated by a comma. Each field is capture by awk and I want to use these variables to create multiple instances of text in an additional file. I have used "while" to capture the variables, but this only runs once.
awk -F ',' '{print $1,$2,$3}' extensions.txt | while read var1 var2 var3; do
echo " <item context=\"active\" type=\"\" fav=\"false\" mod=\"true\" index=\"0\">
<number>$var3</number>
<number_type>sip</number_type>
<first_name>$var1</first_name>
<last_name>$var2</last_name>
<organization>Stackoverflow</organization>
</item>" > test.txt
done
exit
Output for test.txt is:
<item context=\"active\" type=\"\" fav=\"false\" mod=\"true\" index=\"0\">
<number>123456789</number>
<number_type>sip</number_type>
<first_name>Jon</first_name>
<last_name>Doe</last_name>
<organization>Stackoverflow</organization>
</item>
If I use a for loop, it won't retain the 3 variables seperately, but rather take the combined output and place it into a single variable.
exitis pretty pointless; the shell will exit anyway if you delete the line and it is the last (non-blank, non-comment) line in the script.test.txt. Either place the output redirection after, but on the same line as, thedone, or use append mode>>.cat << EOF\n <item context="active...\nEOF