Closed iferres closed 3 months ago
There's a --na
flag.
--na for unmatched data, use blank instead of original data
$ echo -e "lorem,1\nloremipsum,232\nlorem,334\nipsum,214234\nfoobar,4" \
| csvtk mutate -H -f1 -p "(ipsum)" --na \
| csvtk pretty -H
lorem 1
loremipsum 232 ipsum
lorem 334
ipsum 214234 ipsum
foobar 4
Well, if you'd like a NA.
$ echo -e "lorem,1\nloremipsum,232\nlorem,334\nipsum,214234\nfoobar,4" \
| csvtk mutate -H -f1 -p "(ipsum)" --na \
| csvtk replace -H -f3 -p '^$' -r NA \
| csvtk pretty -H
lorem 1 NA
loremipsum 232 ipsum
lorem 334 NA
ipsum 214234 ipsum
foobar 4 NA
Awesome, many thanks!
I may not be seeing the answer, but I think it is not possible right now. I want to create a new column based on the presence or absence (logical) of a substring inside a string column. With grep I get the matches:
With mutate I create a new column with the substring, but if doesn't exists, it returns the whole column:
Would be possible to ask if substring exists, and return it in a logical column? The expected output would be:
Or the possibility of leaving blank (or NA/null) cells in case no matches are detected, something like:
or just leaving them empty.