pavelpok pavelpok - 13 days ago 8
Linux Question

CSV file cleanup in bash

I have a CSV file delimited with ',' which I'd like to use for further processing in a postgres db but not all lines have the correct number of columns.

I'm looking into a way of deleting all lines which don't have a specified number (15) of delimiters.

I've seen a lot of sed/awk solutions but none that would quite achieve what I need. Thanks!

Answer
awk -v FS=',' 'NF==16' <csv>