I have 31 .ctl files in a directory, they looks like this:
load data CHARACTERSET AL32UTF8
infile '../dane/kontakty_Biura_wyborcze.csv' "str '\n'"
append
into table ODI_PUW_OSOBY2
fields terminated by ';'
OPTIONALLY ENCLOSED BY '"' AND '"'
trailing nullcols
( LP CHAR(4000),
WOJEWODZTWO CHAR(4000),
POWIAT CHAR(4000),
GMINA CHAR(4000),
NAZWA_INSTYTUCJI CHAR(4000),
KOD CHAR(4000),
MIEJSCOWOSC CHAR(4000),
ADRES CHAR(4000),
NAZWISKO_I_IMIE CHAR(4000),
FUNKCJA CHAR(4000),
TEL_SLUZB_STACJON_1 CHAR(4000),
TEL_SLUZB_STACJON_2 CHAR(4000),
TEL_SLUZB_STACJON_3 CHAR(4000),
TEL_SLUZB_KOM_1 CHAR(4000),
TEL_SLUZB_KOM_2 CHAR(4000),
FAX_SLUZB_1 CHAR(4000),
FAX_SLUZB_2 CHAR(4000),
EMAIL_SLUZB_1 CHAR(4000),
EMAIL_SLUZB_2 CHAR(4000),
WWW CHAR(4000),
TYP CONSTANT "Biura wyborcze.",
ODI_SESJA_ID CONSTANT "20130717144702"
ODI_STATUS CONSTANT "0",
IMIE EXPRESSION "pg_odi_utils.zwroc_imiona(pg_odi_utils.usun_przyrostki(:NAZWISKO_I_IMIE),0)",
NAZWISKO EXPRESSION "pg_odi_utils.zwroc_nazwisko(pg_odi_utils.usun_przyrostki(:NAZWISKO_I_IMIE),0)"
)
There are 31 files like this. I need to replace value in this line:
ODI_SESJA_ID CONSTANT '20130717144702'
to new timestamp, the same for all files. Current timestamp is not known (I mean value that exists in file currently, in this case '20130717144702').
So I need to (for each file found in directory):
- find line starting from ODI_SESJA_ID
- replace value after 'ODI_SESJA_ID CONSTANT ' with new one
- the rest lines in file should stay untouched
What is the best way to do this using bash? Should I use sed or similar tools? How?