Hi I have an input file in this format.
[Header A]
key1 value1
key2 value2
[Header B]
header1 header2 header3 // separated by tab
1 2 3 //separated by tab
a b c //separated by tab
[Header C]
a
b
c
I have to output whatever is in HeaderB as another csv file So the CSV file will look like
header1,header2,header3
1,2,3
a,b,c
I wrote a python script to do that but the requirement it to do it via a shell command. I don't have much idea about writing complicated shell commands. Can someone help me.
Thanks
This will work for you:
awk -F'\t' '/\[Header B\]/{f=1;next} /^$/{f=0} f{gsub(/\t/,",");print}' file
$ awk -F'\t' '/\[Header B\]/{f=1;next} /^$/{f=0} f{gsub(/\t/,",");print}' file
header1,header2,header3
1,2,3
a,b,c
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With