Reputation:
I have three files with the following contents:
one.txt
a
b
c
two.txt
1
2
3
three.txt
Some text with all kinds of characters (but no single quote).
More text, also with "all kinds of characters" (and no single quote either).
Same as before.
I want to combine the three files into:
'a', '1', 'Some text with all kinds of characters (but no single quote).'
'b', '2', 'More text, also with "all kinds of characters" (and no single quote either).'
'c', '3', 'Same as before.'
that is, I want the string ', '
(i.e. single quote, comma, space, single quote) as delimiter between the three files, and – if you want to try your hand at an advanced answer – a '
a the beginning and end of each new line.
Upvotes: 2
Views: 1786
Reputation: 784998
Using paste
with awk
:
paste one.txt two.txt three.txt | awk -F '\t' -v SQ="'" -v OFS=', ' '{
for (i=1; i<=NF; i++) printf "%s%s%s%s", SQ, $i, SQ, (i<NF)?OFS:ORS}'
'a', '1', 'Some text with all kinds of characters (but not single quote).'
'b', '2', 'More text, also with "all kinds of characters" (and no single quote either).'
'c', '3', 'Same as before.'
Upvotes: 1