csvfilter icon indicating copy to clipboard operation
csvfilter copied to clipboard

fields don't work

Open lk-jeffpeck opened this issue 6 years ago • 4 comments

$ csvfilter -f 1,2,3 file.csv

Expected: Output columns 1, 2, and 3 from file.csv for all rows

Actual: Only outputs columns 1, 2, and 3 from the first row.


It looks like the reason for this is:

fields = map(int, options.fields.split(',')) if options.fields else None

... which is being consumed after the first row:

output = [row[i] for i in self.fields if len(row) > i]

after which self.fields becomes an empty array: []

A solution would be:

fields = list(map(int, options.fields.split(','))) if options.fields else None

This PR should resolve: https://github.com/codeinthehole/csvfilter/pull/12

lk-jeffpeck avatar Mar 07 '18 22:03 lk-jeffpeck

Why hasnt this been merged in yet? The tool is broken.

In the meantime, if anyone is trying to get stuff done: pip install --upgrade git+https://github.com/lk-jeffpeck/csvfilter.git@ec433f14330fbbf5d41f56febfeedac22868a949

That will install Jeffs pull request on your machine and let you get on with your work.

Thanks Jeff btw

joaomcarlos avatar Mar 19 '19 09:03 joaomcarlos

@silentwarrior @lk-jeffpeck Thanks for the fix and for the link to the fix.

keenhl avatar Jul 09 '19 20:07 keenhl

+1 for me with @joaomcarlos fix it works perfectly

pinturic avatar Oct 25 '22 08:10 pinturic

Thanks @lk-jeffpeck @joaomcarlos fix worked for me too 🙌

@codeinthehole Any chance it could be merged?

Eddie901 avatar Jun 07 '23 08:06 Eddie901