Issue
I've got a text file with the following pattern:
06:52:25 -> TRANSACTION START
06:52:26 - line1
06:52:27 - line2
06:52:29 -> TRANSACTION END*
06:53:24 -> TRANSACTION START
06:53:25 - line3
06:53:40 - line4
06:53:52 -> TRANSACTION END
I would like to separate every occurrence of starting transactions and ends into separate files
Solution
Try:
awk '/TRANSACTION START/{file="trans_"cont++".txt"}{print $0 >> file}' inputfile
Explanation:
/TRANSACTION START/{file="trans_"cont++".txt"}
: When the START
pattern is matched the target file name is updated.
{print $0 >> file}
: Print every line in the current file with >>
to avoid overwrite.
Answered By - Juan Diego Godoy Robles