I have a file
instrument.xml
bash-4.1$ more instrument.xml
<instr instr_id="CPT-2380950-011-001-826" valor_ch="" instr_type="CurrentAccount" instr_name="CPT-2380950-011-001-826" qn_type="1" ccy_code="GBP" cnt_code="CH" date_issue="2002-05-29 00:00:00" int_rate="0.08000000" eusd_scope="0" cmnt="CRD" status="1"/>
<instr instr_id="VAL-0000001-000" isin="0000001-000 " valor_ch="0000001-000" instr_type="Share" instr_name="******ON" qn_type="1" ccy_code="999" cnt_code="XX" int_rate="0.00000000" eusd_scope="0" cmnt="200" status="1"/>
<instr instr_id="CPT-2411550-011-000-826" valor_ch="" instr_type="CurrentAccount" instr_name="CPT-2411550-011-000-826" qn_type="1" ccy_code="GBP" cnt_code="CH" date_issue="2002-08-02 00:00:00" int_rate="0.08000000" eusd_scope="0" cmnt="CRD" status="1"/>
Requirement: I need to change [date time] eg 2002-05-29 00:00:00 to [dateTtime] eg2002-05-29T00:00:00 anywhere in the file. --Some lines wont have date in them so i need to search for date pattern and then do my change --and the columns vary in length sed 13 was a very amateur attempt looking for the 13th space(please neglect)
My futile attempts:
sed "s/[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]/&T/" instrument.xml
grep "[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]" test.xml | sed 's/ //13' >instrument.xml ( it doesn’t give me all )
sed "s/[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]/&T~+/" instrument.xml | tr "~" "\n" | sed 's/^+./+/g' ( unable to join only lines which have + in them)
test.xml,test.txt, orinstrument.xml? (2) Do you need to change2002-05-29 00:00:00to2002-05-29T00:00:00anywhere in the file, or do you need to change space toTin any date/time string of the indicated format?s/ //13come from? (5) Research regular expressions, specifically sub-expressions.