I have some directory with multiple files with the extention .failed This the number of files can change every day. This files have the following format:
file1.failed:
FHEAD|4525|20170109000000|20170125024831
THEAD|150001021|20170109121206||
TDETL|4000785067||1|EA|||RETURN|||N
TTAIL|1
THEAD|150001022|20170109012801||
TDETL|4000804525||1|EA|||RETURN|||N
TTAIL|1
FTAIL|6
I need to extract all the text between THEAD| and |2 to a output file. im trying the following and it works only if i have only one file in the directory.
sed -n 's:.*THEAD|\(.*\)|2.*:\1:p' <*.failed >transactions.log
The output is: transactions.log:
150001021
150001022
Now how can i do the same but for multiple files?(undetermined number of files).
Also it is possible to add the filename in every line of the output file as follows?
expected output:
file1.failed,150001021
file1.failed,150001022
file2.failed,150001023
file2.failed,150001024
file2.failed,150001025
file2.failed,150001026
file3.failed,150001027
file3.failed,150001028
Thanks in Advance,