alyr1481
alyr1481

Reputation: 31

LINUX script to check length of each field in a csv file

Basically the title says it all. I could do with some help in writing a little bash or ksh script that can check the length of every field in a .csv file and quit the script with an error if a field length is over 50 characters.

I have already done a quick bit of research but haven't found anything that's exactly what i want!

Thanks in Advance!

Upvotes: 0

Views: 1131

Answers (1)

lnrdo
lnrdo

Reputation: 406

—How to deal with CSV files in bash? —You do not. PERIOD

Unless you are generating the CSV yourself you should not do it with bash alone as the CSV format can be tricky.

The naïve answer would be to split each line on commas, but this is not robust and you should probably use perl's Text::CSV (package libtext-csv-perl on Debian and derivatives).

You may install some CSV parsers to help you with this job:

You probably should probably move to a general purpose language like Perl or Python to accomplish this task.

Upvotes: 2

Related Questions