Hi there! I have a simple log file which is very messy and I need it to be neat. The file contains log headers but are all jumbled up together therefore I need to sort the log files according to the log headers. There are no static number of lines that means that there is no fix number of lines for the each header of the text file. And I am using AWK to sort out the headers.
The Log files goes something like this:
Car LogFile Header
<text>
<text>
<text>
Car LogFile Header
<text>
Car LogFile Header
<and so forth>
It would be outputted like this:
Car LogFile Header
<text>
<text>
<text>
-------------------
Car Logfile Header
<text>
<text>
I have done up/searched a simple code but it does not seem to be working. Can someone please guide me? Thanks!
#!/bin/bash
# usage: pargrep <infile> <searchpattern>
inFile="$1"
searchString="$2"
awk '
BEGIN {
FS="\n"
RS="-----"
}
/'"$searchString"'/ { print }
' ${inFile}