Problem:

– You have several CSV file that have a title that needs to change.

In my example I had a column name that was need to change from “Time(edt)” to just “Time”

To run a test:

note:  no special backslash needed for “(” or “)”

You can glob the files and it will do all of them.

sed 's/Time(edt)/Time/g' KDCA_3_day_Y*.csv

Add the -i to do the deed in place

 

sed -i 's/Time(edt)/Time/g' KDCA_3_day_Y*.csv

For BSD – I got an error

 

[jon2allen@freebsd12_3 ~/github/weather_obs]$ sed -i 's/Time(edt)/Time/g' KDCA_3_day_Y*.csv
sed: 1: "KDCA_3_day_Y2022_M09_D2 ...": invalid command code K

The man page suggest that the -i flag can have a backup extension, and a zero byte would ignore it which doesn’t seem to be the case.

 

sed -ibak 's/Time(edt)/Time/g' KDCA_3_day_Y*.csv

It simply tacks on the extension to the end.

 bsduser  bsduser    1265 Nov  9 11:05 KDCA_3_day_Y2022_M09_D27_H10.csv
 bsduser  bsduser    1270 Sep 27 23:21 KDCA_3_day_Y2022_M09_D27_H10.csvbak

 

Leave a Reply