BurntSushi / xsv

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

Is it possible to generate a new csv from the associated fields of two csv's? #314

Closed photkey closed 1 year ago

photkey commented 1 year ago
csv1, id is the unique field and reads as follows id name other
1 a dfs
2 a sdfsf
3 b sfs
4 b fsdsd
5 c fsdsdf
6 c sfs
7 d fdssd
8 d fssd

csv2, nameis the unique field and reads as follows. name age
a 18
b 22
c 23
d 22

csv2.nameis associated with csv1.name and what I want now, is to insert the csv2.age field in csv1 to generate a new csv file in the following format.

id name age other
1 a 18 dfs
2 a 18 sdfsf
3 b 22 sfs
4 b 22 fsdsd
5 c 23 fsdsdf
6 c 23 sfs
7 d 22 fdssd
8 d 22 fssd

Can you tell me if xcv can do this? If so, can you tell me how the command should be written?

BurntSushi commented 1 year ago

Why did you close the issue? If you found out how to do it, then please share it with other folks so that they can benefit too. :-)

photkey commented 1 year ago

@BurntSushi Because I read up on the xcv documentation and found it so easy to implement, xcv really is so good! xsv join --no-case name csv1.csv name csv2.csv |xsv select 1,2,5,3| xsv table