简体   繁体   中英

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!

—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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM