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

New feature: csvtk join to prefix only duplicated column names #246

Closed
2 tasks done
stas-malavin opened this issue Sep 5, 2023 · 3 comments
Closed
2 tasks done

Comments

@stas-malavin
Copy link

Prerequisites

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

Describe your issue

I would like to have the possibility to prefix only duplicated column names.
The second and third examples below showcase the desired effect of the imaginary --prefix-duplicates flag.

$ csvtk join --prefix-filename \
    <(echo -e 'name,attr,tool\nStas,stubborn,tube\nShenwei,smart,computer') \
    <(echo -e 'name,attr,food\nStas,microbiologist,sandwich\nShenwei,computer scientist,noodles') | \
    csvtk pretty
name      63-attr    63-tool    62-attr              62-food 
-------   --------   --------   ------------------   --------
Stas      stubborn   tube       microbiologist       sandwich
Shenwei   smart      computer   computer scientist   noodles 

$ csvtk join --prefix-filename --prefix-duplicates\
    <(echo -e 'name,attr,tool\nStas,stubborn,tube\nShenwei,smart,computer') \
    <(echo -e 'name,attr,food\nStas,microbiologist,sandwich\nShenwei,computer scientist,noodles') | \
    csvtk pretty
name      63-attr    tool       62-attr              food 
-------   --------   --------   ------------------   --------
Stas      stubborn   tube       microbiologist       sandwich
Shenwei   smart      computer   computer scientist   noodles 

$ csvtk join --prefix-duplicates\
    <(echo -e 'name,attr,tool\nStas,stubborn,tube\nShenwei,smart,computer') \
    <(echo -e 'name,attr,food\nStas,microbiologist,sandwich\nShenwei,computer scientist,noodles') | \
    csvtk pretty
name      attr       tool       attr1                food 
-------   --------   --------   ------------------   --------
Stas      stubborn   tube       microbiologist       sandwich
Shenwei   smart      computer   computer scientist   noodles 

It may also be a default behavior.
Thank you!

@shenwei356
Copy link
Owner

Added a new flag -P/--prefix-duplicates, but it needs to be used along with --prefix-filename`.

$  csvtk join --prefix-filename --prefix-duplicates\
    <(echo -e 'name,attr,tool\nStas,stubborn,tube\nShenwei,smart,computer') \
    <(echo -e 'name,attr,food\nStas,microbiologist,sandwich\nShenwei,computer scientist,noodles') | \
    csvtk pretty
name      attr       tool       62-attr              food    
-------   --------   --------   ------------------   --------
Stas      stubborn   tube       microbiologist       sandwich
Shenwei   smart      computer   computer scientist   noodles 

@stas-malavin
Copy link
Author

stas-malavin commented Sep 5, 2023

You're blasting-fast, thank you! :)

@stas-malavin
Copy link
Author

It works, confirm

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

No branches or pull requests

2 participants