wireservice / csvkit

A suite of utilities for converting to and working with CSV, the king of tabular file formats.
https://csvkit.readthedocs.io
MIT License
6.03k stars 603 forks source link

csvgrep is always returning first line in data file even when it doesn't match anything in pattern file #1177

Closed barrymoore closed 2 years ago

barrymoore commented 2 years ago

Hi all,

On csvgrep version 1.0.7 I am always getting the first line of my data file returned even though it doesn't have a match in the pattern file. I've tried this a few different ways with different files, columns and patterns etc. - the issue occurs in all cases. The very simple test below reproduces the issue for me.

echo 'a' > test_pattern.txt
echo 'b' > test_data.txt
csvgrep -c 1 -f test_pattern.txt test_data.txt

The above always returns 'b', but even though 'b' is not in the test pattern.txt file. Seems like a pretty clear (and kind of scary) bug to me.

Barry

jpmckinney commented 2 years ago

The first row is considered the header row, and so it is always returned, since you typically want to keep the headers...

If you don't have a header row use --no-header-row.