I have CSV files with headers like this
MyFirstCol,MySecondCol,MyThirdCol,.....MyLastRealCol,ppp,qqq,rrr
The columns ppp, qqq, etc I want to set to columns with empty headers. (I do not want to delete them!) So I want a resulting CSV with a header like this:
MyFirstCol,MySecondCol,MyThirdCol,.....MyLastRealCol,,,
(Note the empty, but present columns at the end.)
Is there a way to do this with miller?(*) I tried
mlr --csv rename -r '"^(.){3}$",' myFile.csv
but this command folds all the matching columns into one! :-(
(*) I do know how to hack this together with a search-replace command in sed , but I don't like it as a general solution, because sed is not aware of the CSV's column structure. Therefore I am hoping for a solution with miller.
If I understand correctly, just remove the empty columns
If you want to use rename, the command is
But please note in Miller you cannot have a CSV whit two or more fields with the same name. And if you have
the last fields have the same empty field name. Then you can add a numeric progressive heading, then apply a search & replace to the first data row, and at the end remove the numeric heading.
Starting from
and running
you will have
Some points:
-Nadd and remove the numeric heading;if(NR==1)to apply the put verb only to first data row that here isfield1,field2,ppp,qqq,zzz