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

align-center and align-right for specific columns #240

Closed
tolot27 opened this issue Aug 8, 2023 · 2 comments
Closed

align-center and align-right for specific columns #240

tolot27 opened this issue Aug 8, 2023 · 2 comments

Comments

@tolot27
Copy link

tolot27 commented Aug 8, 2023

I'm using csvtk v0.26 and it would be great if pretty can be extended to align specific columns only, i. e. by specifying column numbers with -m, --align-center and -r, --align-right.

Example of current output:

echo -e "contigs,sum_bases,cov,species\n37,31322,10.8,Homo sapiens\n1,11028,2388.5,Orthoflavivirus" | csvtk pretty -S plain
contigs   sum_bases   cov      species
37        31322       10.8     Homo sapiens
1         11028       2388.5   Orthoflavivirus

or

echo -e "contigs,sum_bases,cov,species\n37,31322,10.8,Homo sapiens\n1,11028,2388.5,Orthoflavivirus" | csvtk pretty -S plain -r
contigs   sum_bases      cov           species
     37       31322     10.8      Homo sapiens
      1       11028   2388.5   Orthoflavivirus

desired output:

echo -e "contigs,sum_bases,cov,species\n37,31322,10.8,Homo sapiens\n1,11028,2388.5,Orthoflavivirus" | csvtk pretty -S plain -m 1 -r 2,3
contigs   sum_bases      cov   species
  37          31322     10.8   Homo sapiens
   1          11028   2388.5   Orthoflavivirus
@shenwei356
Copy link
Owner

That's useful.

@shenwei356
Copy link
Owner

shenwei356 commented Aug 11, 2023

Supported.

Use binaries here: #91 (comment)

$ echo -e "contigs,sum_bases,cov,species\n37,31322,10.8,Homo sapiens\n1,11028,2388.5,Orthoflavivirus"  \
    | csvtk pretty -S plain -m 1 -r 2,3
contigs   sum_bases      cov   species        
  37          31322     10.8   Homo sapiens   
   1          11028   2388.5   Orthoflavivirus

$ echo -e "contigs,sum_bases,cov,species\n37,31322,10.8,Homo sapiens\n1,11028,2388.5,Orthoflavivirus" \
   | csvtk pretty -S plain -m contigs -r sum_bases,cov
contigs   sum_bases      cov   species        
  37          31322     10.8   Homo sapiens   
   1          11028   2388.5   Orthoflavivirus

$ csvtk pretty testdata/names.csv -r 1,username -m first_name
┏━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━┓
┃ id ┃ first_name ┃ last_name ┃ username ┃
┣━━━━╋━━━━━━━━━━━━╋━━━━━━━━━━━╋━━━━━━━━━━┫
┃ 11 ┃    Rob     ┃ Pike      ┃      rob ┃
┣━━━━╋━━━━━━━━━━━━╋━━━━━━━━━━━╋━━━━━━━━━━┫
┃  2 ┃    Ken     ┃ Thompson  ┃      ken ┃
┣━━━━╋━━━━━━━━━━━━╋━━━━━━━━━━━╋━━━━━━━━━━┫
┃  4 ┃   Robert   ┃ Griesemer ┃      gri ┃
┣━━━━╋━━━━━━━━━━━━╋━━━━━━━━━━━╋━━━━━━━━━━┫
┃  1 ┃   Robert   ┃ Thompson  ┃      abc ┃
┣━━━━╋━━━━━━━━━━━━╋━━━━━━━━━━━╋━━━━━━━━━━┫
┃ NA ┃   Robert   ┃ Abel      ┃      123 ┃
┗━━━━┻━━━━━━━━━━━━┻━━━━━━━━━━━┻━━━━━━━━━━┛

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