I have 3 source files.
1.txt
- template.
<field name="COL1" label="COL2" data-source="COL1" classes="attribute" category="Attribute"/>
2.txt
- variables for COL1.
IDNName
BusinessUnit
WWB
IncentiveID
3.txt
- variables for COL2.
IDN Name
Business Unit
WWB
Incentive ID
I need output like this (take 1st line from 2.txt
and 3.txt
and insert to template, then take 2nd line from 2.txt
and 3.txt
and insert to template, etc...)
<field name="IDNName" label="IDN Name" data-source="IDNName" classes="attribute" category="Attribute"/>
<field name="BusinessUnit" label="Business Unit" data-source="BusinessUnit" classes="attribute" category="Attribute"/>
<field name="WWB" label="COL2" data-source="WWB" classes="attribute" category="Attribute"/>
<field name="IncentiveID" label="Incentive ID" data-source="IncentiveID" classes="attribute" category="Attribute"/>
Is possible to do it by one for
condition with sed
? I tried, but I don't know how to combine 2 files in one row.
for i in $(cat 2.txt); do cat 1.txt | sed 's/COL1/'$i'/g'; echo; done
Thanks.
If you know that there's a "safe" delimiter such as TAB that may not occur in your 2.txt or 3.txt files, then you could do
Alternatively with GNU parallel:
However if you're actually working with XML data, then you might want to use a proper XML tool -
xmlstarlet
is one possibility, but since I'm more familiar withjq
here's an option using kislyuk'sxq
from yq: Command-line YAML/XML/TOML processor - jq wrapper for YAML, XML, TOML documents