-
Notifications
You must be signed in to change notification settings - Fork 227
Closed
Description
Hi,
I'm sure that's a direct and better way to do it, but I do not find it :(
I have in example this CSV with a carriage return in one of its field names, and my goal is to use DSL to replace it with a space.
"field
A",field B
1,2
3,3
6,6
To do it you could run
mlr -I --csv -N put -S 'if (NR == 1) {for (k in $*) {$[k] = clean_whitespace(gsub($[k], "\n", " "))}}' input.csv
- using
-N
(a great new feature) you apply--implicit-csv-header
and--headerless-csv-output
and the row with field names is no more the heading, but the first data row; - then I apply a search and replace only to the first row (using
NR == 1
); - and at the end, since we have
--headerless-csv-output
, the first row becomes again the heading.
The result will be
field A,field B
1,2
3,3
6,6
Probably not so useful, but it has saved my day.
Thank you always @johnkerl