shenwei356 / csvtk

A cross-platform, efficient and practical CSV/TSV toolkit in Golang
http://bioinf.shenwei.me/csvtk
MIT License
999 stars 84 forks source link

mutate2 - Column name with special charactors taken as a variable #207

Closed MostafaYA closed 1 year ago

MostafaYA commented 1 year ago

Prerequisites

Describe your issue

Hi, I am using csvtk mutate2 as a part of a script to concatenate results of multiple columns. I take sample name as a variable but special character makes a problem here

> cat test.tsv
Gene_position   ref IP-e-D-1-9  f1  f2
gyrA_43 V   V   gyrA    43
gyrA_71 D   D   gyrA    71
> sample=IP-e-D-1-9 ##variable 
> cat test.tsv | csvtk mutate2 -t -e ' $f1 + "_" + $ref + "" + $f2 + "" + ${  $sample }   '  -n position
[ERRO] column " $sample " not existed in file: -

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).

shenwei356 commented 1 year ago

Don't leave spaces in ${}, and note the quotes.

$ cat test.tsv \
    | csvtk mutate2 -t -e "\$f1 + '_' + \$ref + '_' +  \$f2 + '_' + \${$sample}"  -n position \
    | csvtk pretty -t
Gene_position   ref   IP-e-D-1-9   f1     f2   position
-------------   ---   ----------   ----   --   -----------
gyrA_43         V     V            gyrA   43   gyrA_V_43_V
gyrA_71         D     D            gyrA   71   gyrA_D_71_D
MostafaYA commented 1 year ago

thanks!!