Extract record in shell script,so far using awk without success

hello, I require help in the following. There is a report similar to the ones shown here. I need to do couple of things

10/07 12:47            0003210042 R TENN ANVISER0 DELF96A.V1.O.TENRREG       120710 124657 U 00000 DELFOR          1       4331
10/07 12:47            0003210043 S TENN ANVISER0 DELF96A.V1.O.TENRREG       120710 134658 U 00000 DELFOR          1       4244
10/07 15:47            0003210043 S TENN ANVISER0 DELF96A.V1.O.TENRREG       120710 155658 U 00000 DELFOR          1       4244

1> Check for all records which has only "S" in the above records, extract
eg. The second record is "S" (in the 4th col)

2> Pick up the 2nd col and 9th col i.e 12:47 and 134648 to show something like this

So the output should look something like this

Sch Date/Time       Directn    Destination        File Format           EERP Date/Time
=============      =======    ===========        ===========           ==============
10/07 12:47          S        ANVISER0    DELF96A.V1.O.TENRREG       120710 13:47     
10/07 15:47          S        ANVISER0    DELF96A.V1.O.TENRREG       120710 15:57     

I am struggling to get awk to get the display. Would there be an easier way other than awk. The records will be in a separate file

With awk:

awk '
BEGIN{print "Sch Date/Time\tDirectn\tDestination\tFile Format\t\tEERP Date/Time"
      print "==============\t=======\t===========\t===========\t\t=============="
      OFS="\t"} 
$4=="S"{
hh=substr($9,1,2)
mm=substr($9,3,2)
ss=substr($9,5,2)
$9=(ss+0>=30?(mm==59?(hh==23?"00:00":(hh+1)":00"):(hh":"(mm+1))):(hh":"mm))
print $1" "$2,$4,$6,$7,$8" "$9}' inputfile

Output:

Sch Date/Time   Directn Destination     File Format             EERP Date/Time
==============  ======= ===========     ===========             ==============
10/07 12:47     S       ANVISER0        DELF96A.V1.O.TENRREG    120710 13:47
10/07 15:47     S       ANVISER0        DELF96A.V1.O.TENRREG    120710 15:57

Change the static text and/or the logic as per your requirement...

1 Like

thank you so much elixir_sinari, it works like charm...:smiley: