BurntSushi / xsv

A fast CSV command line toolkit written in Rust.
The Unlicense
10.29k stars 317 forks source link

search or filter multi value #252

Open Grummfy opened 3 years ago

Grummfy commented 3 years ago

Hello, I have two "big" csv files : A & B

I would like to split theses files into smaller chunks. But I would like that there is still some consistency between chunks. So I would like that if I have a chunk n, all "Id" from An that exist in B would be present in Bn.

So I see the split, I see the order & index, I see the select and the search. So every of theses element will help. But search only allow to look for one value. For now, the only way I see to do this, is to select in B the value that will be exist in An and push it inside the Bn, but this seems not very helpfull.

So did you see a way to do this? For me it seems to me a basic behaviour?

BurntSushi commented 3 years ago

I don't understand what you want. Please show what you've tried, some input, the actual output and the output you want.

Grummfy commented 3 years ago

No problem

So here is an example

A.csv

Id,name,value
1,foo,42
5,bar,105
42,stuff,123456

B.csv

hello,2020-01-01,5
baz,2020-01-01,5
yoloooo,2020-05-20,1
funnn,2020-05-20,42

So the expected output would be Split A in chunks A_0.csv

Id,name,value
1,foo,42
5,bar,105

A_0.csv

Id,name,value
1,foo,42
42,stuff,123456

split B, related to field Id in A that match third column of B B_0.csv

hello,2020-01-01,5
baz,2020-01-01,5
yoloooo,2020-05-20,1

B_1.csv

funnn,2020-05-20,42

so the command will be

xsv split -s 2 A.csv

And then I will do

xsv search -n -s 3 1 B.csv >> B_0.csv
xsv search -n -s 3 5 B.csv >> B_0.csv
xsv search -n -s 3 42 B.csv >> B_1.csv

So having something like xsv search -n -s 3 --value=1 --value=5 B.csv >> B_0.csv would be nice