I am using RHEL 6.9. I got a requirement to group the records in a file.The file content as shown below.
#### FAILED JOBS IN XXX #####
1> ABCD failed in the project XXX
2> HJK Job is in compiled state in the project XXX
3> ILKD failed in the project XXX
4> DFG failed in the project XXX
5> HOI Job is in compiled state in the project XXX
6> TYU failed in the project XXX
My requirement is to group all the record with message containing Job is in compiled state into one area and other group with rest all jobs. So my expected output is
given below
#### FAILED JOBS IN XXX#####
1> ABCD failed in the project XXX
2> ILKD failed in the project XXX
3> DFG failed in the project XXX
4> TYU failed in the project XXX
#### COMPILED JOBS IN XXX#####
1> HJK Job is in compiled state in the project XXX
2> HOI Job is in compiled state in the project XXX
awk '
NR == 1 {print
next
}
! NF {next
}
/failed/ {$1 = ++FCNT ">"
print
next
}
{$1 = ++CCNT ">"
C[CCNT] = $0
}
END {print ORS "#### COMPILED JOBS IN XXX#####" ORS
for (c=1; c<=CCNT; c++) print C[c]
}
' file
#### FAILED JOBS IN XXX #####
1> ABCD failed in the project XXX
2> ILKD failed in the project XXX
3> DFG failed in the project XXX
4> TYU failed in the project XXX
#### COMPILED JOBS IN XXX#####
1> HJK Job is in compiled state in the project XXX
2> HOI Job is in compiled state in the project XXX
Hi All, Now my requirement is change, but almost similar to the above one. But using the above code it is not working.I tried different option but its not giving correctly.
My input file is given below
#### RUNNING JOBS IN SITE#####
#### NOT RUNNING JOBS IN SITE#####
1> XXX Job is Running in the project WQW
2> SSS Job is Running in the project WQW
3> DDD Job is Running in the project WQW
4> EEE Job is Running in the project WQW
5> FFF Job is not running(Failed/Stopped/Reset/Not Compiled/Compiled) in the project WQW
My expected output file is given below
#### RUNNING JOBS IN SITE#####
1> XXX Job is Running in the project WQW
2> SSS Job is Running in the project WQW
3> DDD Job is Running in the project WQW
4> EEE Job is Running in the project WQW
#### NOT RUNNING JOBS IN SITE#####
1> FFF Job is not running(Failed/Stopped/Reset/Not Compiled/Compiled) in the project WQW
I tried this code as given below, but it didn't work
awk '
NR == 1 {print
next
}
! NF {next
}
/is running/ {$1 = ++FCNT ">"
print
next
}
{$1 = ++CCNT ">"
C[CCNT] = $0
}
END {print ORS "#### NOT RUNNING JOBS CCM SITE#####" ORS
for (c=1; c<=CCNT; c++) print C[c]
}
'