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

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

Closed
4 tasks
MostafaYA opened this issue Aug 15, 2023 · 4 comments
Closed
4 tasks

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

MostafaYA opened this issue Aug 15, 2023 · 4 comments
Labels

Comments

@MostafaYA
Copy link

Prerequisites

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

Describe your issue

  • describe the problem
  • provide a reproducible example

Hi, something has been changed in csvtk mutate2 version 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).

@MostafaYA MostafaYA changed the title csvtk mutate2 version 0.27.0 gives errors when use column names csvtk mutate2 version 0.27.0 gives errors when use column numbers Aug 15, 2023
@shenwei356 shenwei356 added the bug label Aug 15, 2023
@shenwei356
Copy link
Owner

@MostafaYA
Copy link
Author

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
Copy link
Owner

shenwei356 commented Aug 15, 2023

${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
Copy link
Author

谢谢 :)

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

No branches or pull requests

2 participants