Hi
I want to apply some logic to below (FROM) output and get it to the desired output
FROM
cat jk3:
APP1 APP1
10 1366222 | 10 1366229
13 12559230 | 13 12559239
APP2 APP2
APP3 APP3
10 1366222 | 10 1366229
13 12559230 | 13 12559239
APP4 APP4
DESIRED output:
APP1
---------------
ID Gaps Time of gap
[10] [1366222 =>1366229] 08:00 - 08:30
[13] [12559230=>255923] 08:00 - 08:30
APP2
---------------
ID Gaps Time of gap
APP3
---------------
ID Gaps Time of gap
[10] [1366222 =>1366229] 08:00 - 08:30
[13] [12559230=>255923] 08:00 - 08:30
APP4
---------------
ID Gaps Time of gap
The logic is, if the line contains APP word, just print the whole line. If not, print first column inside [], print 2nd column then have a '=>' seperator and then print fifth column. Then we want to print two variables which show start and end time.
I can do half of what I need using awk, however im unable to output the start time and end time variables using awk
awk '{ if ($1 ~ /APP/) print $1; else print "["$1"] \t\["$2"=>"$5"] "}' jk3
APP1
[10] [1366222=>1366229]
[13] [12559230=>12559239]
APP2
APP3
APP4
[10] [1366222=>1366229]
[13] [12559230=>12559239]
Ie This is what I want to do but seems I cant do using awk (ie adding two variables $PREVIOUS_CHECK_DATE$CURRENT_CHECK_DATE to end of the line if it doesn't contain APP)
I get below errors when trying this method
awk '{ if ($1 ~ /APP/) print $1; else print "["$1"] \t\["$2"=>"$5"] \t\"$PREVIOUS_CHECK_DATE$CURRENT_CHECK_DATE }' jk3
awk: { if ($1 ~ /APP/) print $1; else print "["$1"] \t\["$2"=>"$5"] \t\"$PREVIOUS_CHECK_DATE$CURRENT_CHECK_DATE }
awk: ^ unterminated string
Have also tried to do following but not getting what I need. Can anyone see what im doing wrong or what is the best method. Many Thanks
while read line
do
grep APP $line > /dev/null
RET_CODE=$?
if [ $RET_CODE -eq 0 ]
then
echo $line
else
echo "$line $PREVIOUS_CHECK_DATE $CURRENT_CHECK_DATE"
fi
done < jk3