Closed MostafaYA closed 2 years ago
Here's a way, when no column names are given, add-header
add fake colnames:
$ seq 5 | csvtk transpose -Ht
1 2 3 4 5
$ seq 5 | csvtk transpose -Ht \
| csvtk add-header -t
[WARN] colnames not given, c1, c2, c3... will be used
c1 c2 c3 c4 c5
1 2 3 4 5
$ seq 5 | csvtk transpose -Ht \
| csvtk add-header -t \
| csvtk rename -t -f 1,2 -n sample,name
[WARN] colnames not given, c1, c2, c3... will be used
sample name c3 c4 c5
1 2 3 4 5
$ seq 5 | csvtk transpose -Ht \
| csvtk add-header -t \
| csvtk rename -t -f 1,2 -n sample,name \
| csvtk rename2 -t -f -1,-2 -p '.+' -r Gene
[WARN] colnames not given, c1, c2, c3... will be used
sample name Gene Gene Gene
1 2 3 4 5
Thank you very much for your quick reply. It worked perfectly.
Another question: How can I use csvtk cut
to discard only the last column?
Hmm, no direct way, you have to know the number of columns first
$ csvtk cut -t -f 1-$(expr $(csvtk ncol -t data.tsv) - 1) data.tsv
Prerequisites
csvtk version
Describe your issue
add-header
to add headers to an automatically generated table. The thing is that the number of columns in this table is different every time it is created, and I want to append header name "Gene" to the table from the third column to the last column some thing like thisI do the following workaround
I wonder if such a feature already exists in
csvtk
and I am not aware of it.Thank you
I'm grateful to users who have greatly helped to report bugs and suggested new features.
I may respond to issues or fix bugs quickly, but I usually implement new features periodically (two or more weeks).