I have a file source.txt like the following:
Executing resource: L:\Core\SQL\smpks_fcj_csdovdmt_addon.sql
Failed to execute:
Executing resource: L:\LC\SQL\lcpks_lcdtronl_utils.sql
Executing resource: L:\LS\SQL\cspks_adhoc_charge_sch.sql
Failed to execute:
SHO ERR
Executing resource: L:\LS\SQL\gwpks_ls_adhocsch_operations.sql
Executing resource: L:\LS\SQL\lnpks_synd_services.sql
Failed to execute:
Executing resource: L:\LS\SQL\lspks_facility_contracts.sql
Executing resource: L:\LS\SQL\lspks_fcj_lsdpxlog.sql
Executing resource: L:\LS\SQL\lspks_lsdprmnt_kernel.sql
Failed to execute:
sho err;
From this file I need to get the lines just in front of the sting "Failed to execute:" and put it into a new file result.txt. One more condition, if "Failed to execute:" is followed by "sho err: or "SHO ERR" I dont need that file in the result. The output of the above mentioned file should be:
Executing resource: L:\Core\SQL\smpks_fcj_csdovdmt_addon.sql
Executing resource: L:\LS\SQL\lnpks_synd_services.sql
Please help. Perl script or batch file or Ant script is fine.
If I get an option like, if "Sho err" is there, delete the previous line, its fine.