My personal blog

Convert newline from field filtering csv

2020.07.02

Supposed you have example.txt with following lines:

random123,1245541338292,unusedField
random123,755914356949,unusedField
random123,1666447420906,unusedField
random123,841814584100,unusedField
random123,85899498045,unusedField
random123,103079686442,unusedField
random123,773095309528,unusedField
random123,704375532464,unusedField
random123,1348619892622,unusedField
random123,34737697829747,unusedField

You can get the second column and convert the newline into commas by invoke this command

cat example.txt | awk -F ',' '{print $2}' | sed ':a;N;$!ba;s/\n/,/g'

the output:

1245541338292,755914356949,1666447420906,841814584100,85899498045,103079686442,773095309528,704375532464,1348619892622,34737697829747
comments powered by Disqus