Shell script to extract some records

December 6, 2010 at 00:26:43
Specs: Windows 7
Could you please help me,
i have a file which has the following lines.
i need to extract the fields which are Highlighted
and moreover i want to extract in the following way.
starting from the first column i have to go n(say n=13) lines down and extract "Records" field value.

Oct 03 10:59:53 Phase 2 ended (4 seconds)
CPU Time Status Skew Vertex
0.270 [ : 1] 0% Logs_1.Gather
0.240 [ : 1] 0% Logs_1.Gather_1
0.330 [ : 1] 0% Logs_1.Gather_3
0.200 [ : 1] 0% Logs_1.Trash
0.540 [ : 1] 0% Partition_by_Key
8.470 [ :12] 0% Update_Table_Card_Dtl_2
--------------------------------------------------------------------------------
Data Bytes Records Status Skew Flow Vertex Port
5,040 60 [ : : 1] 0% Flow_10 Partition_by_Key in
5,040 60 [ : : 12] 58% Flow_18 Partition_by_Key out
5,040 60 [ : : 12] 58% Flow_18 Update_Table_Card_Dtl_2 in
0 0 [ : : 12] 0% Flow_19 Update_Table_Card_Dtl_2 reject
0 0 [ : : 12] 0% Flow_19 Logs_1.Gather in
0 0 [ : : 12] 0% Flow_20 Update_Table_Card_Dtl_2 error
0 0 [ : : 12] 0% Flow_20 Logs_1.Gather_1 in
43,248 300 [ : : 12] 0% Flow_21 Update_Table_Card_Dtl_2 log
43,248 300 [ : : 12] 0% Flow_21 Logs_1.Gather_3 in
43,248 300 [ : : 1] 0% Logs_1.Flow_1 Logs_1.Gather_3 out
43,248 300 [ : : 1] 0% Logs_1.Flow_1 Logs_1.Trash in
0 0 [ : : 1] 0% Logs_1.Flow_2 Logs_1.Gather out
0 0 [ : : 1] 0% Logs_1.Flow_3 Logs_1.Gather_1 out
--------------------------------------------------------------------------------
2010-10-03 10:59:56 #--- Ended


Thanks in advance

kanth


See More: Shell script to extract some records

Report •

#1
December 6, 2010 at 09:21:50
Use awk's internal line counter, NR, which is the ordinal number of the current record read:

#!/bin/ksh

awk ' {
if(NR == 1)
   printf("%s %s %s\n", $1, $2, $3)

if(NR == 13)
   print $2

# save last line
f1=$1
f2=$2

}
END {
# print last line
   printf("%s %s\n", f1, f2)
} ' datafile


Report •
Related Solutions


Ask Question