I am trying to grep the line of specific pattern from log file Logfile.txt
and redirecting the output to new text file 1.txt
. Log file has some control ^M
character in it and also those lines will be available between the timestamp lines, so im trying to merge all those multiple lines into single line and trying to append it as shown in the expected result if the previous line contains Execute
pattern in it. But couldn't able to get it as expected
Logfile.txt
1993-01-04 06:24:03,068 INFO b: [Cool: read-189231]: Opening the File
1993-01-04 06:24:13,068 INFO b: [Cool: read-189231]: Checking the content
1993-01-04 06:24:23,148 INFO b: [Cool: read-189231]: Setting the session:
1993-01-04 06:24:25,068 INFO b: [Cool: read-189231]: Checking the content
1993-01-04 06:24:25,068 INFO b: [Cool: read-189231]: Compiling the query
1993-01-04 06:24:27,148 INFO ab: [Cool: read-189231]: Completed
1993-01-04 06:25:22,168 INFO ba: [Cool: read-190983]: Execute ^M
I am just checking the answer ^M
Need your support for the workaround ^M
This log has some control character ^M
1993-01-04 06:25:22,168 INFO a: [Cool: read-190983]: Main Execution completed
1993-01-04 06:25:52,188 INFO ba: [Cool: read-190983]: Execute the line : How are you
1993-01-04 06:26:45,268 INFO a: [Cool: read-190983]: Exiting
Code - My Findings
egrep -wah 'Setting the session:|Checking the line|Completed|Execute|Exiting' Logfile.txt > 1.txt
Expected Result
1993-01-04 06:24:23,148 INFO b: [Cool: read-189231]: Setting the session:
1993-01-04 06:24:25,068 INFO b: [Cool: read-189231]: Checking the line
1993-01-04 06:24:27,148 INFO ab: [Cool: read-189231]: Completed
1993-01-04 06:25:22,168 INFO ba: [Cool: read-190983]: Execute ^M I am just checking the answer ^M Need your support for the workaround ^M This log has some control character ^M
1993-01-04 06:25:52,188 INFO ba: [Cool: read-190983]: Execute the line : How are you
1993-01-04 06:26:45,268 INFO a: [Cool: read-190983]: Exiting
Main Execution completed
gone? Do you really want the^M
kept in output (they'll overwrite each precedent output line)?