csvkit icon indicating copy to clipboard operation
csvkit copied to clipboard

csvclean dry run

Open erin-bristow opened this issue 2 years ago • 2 comments

Hi! I recently updated my csvkit version and I see that the dry-run option was removed in more recent versions. This was really useful for validating CSVs and getting a quick look at which line numbers had issues and the expected vs. found number of columns. Is there a way to replicate this old functionality in the current version or would you recommend reverting to the old version? Thanks!

erin-bristow avatar Aug 26 '24 17:08 erin-bristow

which line numbers had issues and the expected vs. found number of columns

I don't see a change in behavior here?

$ csvclean -a examples/bad.csv 2>&1 >/dev/null
line_number,msg,column_a,column_b,column_c
1,"Expected 3 columns, found 4 columns",1,27,,I'm too long!
2,"Expected 3 columns, found 2 columns",,I'm too short!

csvclean now exits with status 1 (error) if there are errors to report. So, if you just want to know whether it exited cleanly or not, you can check the exit status. Like one of:

if [ csvclean -a examples/bad.csv ]; then echo "my message"; fi
[ csvclean -a examples/bad.csv ] && echo "my message"
csvclean -a examples/bad.csv >/dev/null 2>&1; echo $?

To count the number of errors reported, you can do this:

$ csvclean -a examples/bad.csv 2>&1 1>/dev/null | csvstat --count
2

That is, ignore standard output, redirect standard error to standard output, and count the number of rows.

jpmckinney avatar Aug 26 '24 19:08 jpmckinney

Ah much appreciated! Thanks for the examples

erin-bristow avatar Aug 28 '24 16:08 erin-bristow