Bash - replace string inside all files in directory -


i have 31 .ctl files in directory, looks this:

load data characterset al32utf8   infile '../dane/kontakty_biura_wyborcze.csv' "str '\n'" append table odi_puw_osoby2 fields terminated ';' optionally enclosed '"' , '"' 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 31 files this. need replace value in line:

odi_sesja_id constant '20130717144702' 

to new timestamp, same files. current timestamp not known (i mean value exists in file currently, in case '20130717144702').

so need (for each file found in directory):

  • find line starting odi_sesja_id
  • replace value after 'odi_sesja_id constant ' new one
  • the rest lines in file should stay untouched

what best way using bash? should use sed or similar tools? how?

something like:

sed 's/\(^[ \t]\+odi_sesja_id\ constant\).*/\1 \"newtimestamp\"/' tmp 

should work.

group string retained, adding placeholder (\1) in replacement string. replace newtimestamp whatever value prefer, of course.


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -