shenwei356 / csvtk

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

csvtk mutate2 version 0.27.0 gives errors when use column numbers #242

Closed MostafaYA closed 1 year ago

MostafaYA commented 1 year ago

Prerequisites

Describe your issue

Hi, something has been changed in csvtk mutate2version 0.27.0. It gives errors when use column names

$ echo -e "one,two\na1,a2\n,b2\na2,"     | csvtk mutate2 -n three -e '$one ?? $two'     | csvtk pretty
one   two   three
---   ---   -----
a1    a2    a1   
      b2    b2   
a2          a2 
$ echo -e "one,two\na1,a2\n,b2\na2,"     | csvtk mutate2 -n three -e '$1 ?? $2'     | csvtk pretty
[ERRO] data: [a1 a2], err: No parameter 'shenwei1' found.
[WARN] csvtk pretty: skipping empty input 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

ouch ~

fixed.

MostafaYA commented 1 year ago

Thanks! It worked.

Another question: how can mutate2 accept column name with space.

Here is an example

$ echo -e "one,two\na1,a2\n,b2\na2,"   \
  | csvtk rename -n "one one" -f 1  \
  | csvtk mutate2 -n three -e '$1 ?? $2'  \
  | csvtk pretty

one one   two   three
-------   ---   -----
a1        a2    a1   
          b2    b2   
a2              a2   

This does not work!

echo -e "one,two\na1,a2\n,b2\na2," \
 | csvtk rename -n "one one" -f 1 \
 | csvtk mutate2 -n three -e '$"one one" ?? $two'  \
 | csvtk pretty

[ERRO] Invalid token: '$'
[WARN] csvtk pretty: skipping empty input file: -
shenwei356 commented 1 year ago

${one one}

csvtk mutate2 -h

Variables formats:
  $1 or ${1}                        The first field/column
  $a or ${a}                        Column "a"
  ${a,b} or ${a b} or ${a (b)}      Column name with special charactors,
                                    e.g., commas, spaces, and parentheses
MostafaYA commented 1 year ago

谢谢 :)