Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

collate / concatenate / aggregate sets of files with identical fields #38

Closed
2 tasks done
avilella opened this issue Feb 6, 2018 · 4 comments
Closed
2 tasks done

Comments

@avilella
Copy link

avilella commented Feb 6, 2018

Prerequisites

  • make sure you're are using the latest version by csvtk version
  • read the usage

Describe your issue

I have a collection of worksheets in an xlsx file, each worksheet should be of the same type. I want to collate them together (or concatenate or aggregate, not sure what the best word is), so that the order in which I concatenate them is preserved, but the duplicated headers disappear. I am currently doing this with datamash rmdup 1 below, but I rather have a pure csvtk recipe for this:

csvtk xlsx2csv -n LISTOFWORKSHEETS $meta | csvtk cut -f1 | while read ws; do csvtk xslx2csv -n $ws $meta; done | datamash rmdup 1 -t ',' > final_collated_file.csv

What would be the recipe for this collate operation in csvtk? Thanks in advance.

@shenwei356
Copy link
Owner

shenwei356 commented Feb 6, 2018

I'll add a concat command.

for f in *.xlsx; do csvtk xlsx2csv $f > $f.csv; done

csvtk concat *.xlsx.csv > final.csv

shenwei356 added a commit that referenced this issue Feb 6, 2018
@shenwei356
Copy link
Owner

csvtk concat is available in v0.13.0-dev or later versions.

You can use command:

csvtk xlsx2csv -n LISTOFWORKSHEETS $meta \
    | csvtk cut -f1 \
    | while read ws; do \
        csvtk xslx2csv -n $ws $meta > $meta.$ws.csv ; \
      done;
csvtk concat *.csv > final_collated_file.csv

@avilella
Copy link
Author

avilella commented Feb 6, 2018

Fantastic! Thank you.

@avilella avilella closed this as completed Feb 6, 2018
@shenwei356
Copy link
Owner

You're welcome. Please share with others if you find csvtk useful. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants