Hi, I'm new to AWK and trying to parse through a long list of records and extract fields from them.
sample record:
DN 0
TYPE CDP
STCD TSC
DN 2203
CPND
CPND_LANG ROMAN
NAME
XPLN 27
DISPLAY_FMT FIRST,LAST
TYPE 500
TN 008 0 09 02 MARP DES SAS 17 FEB 2003
DN 2204
CPND
CPND_LANG ROMAN
NAME
XPLN 27
DISPLAY_FMT FIRST,LAST
TN 008 0 09 03 MARP DES SAS 17 FEB 2003
DN 7906
CPND
CPND_LANG ROMAN
NAME
XPLN 27
DISPLAY_FMT FIRST,LAST
TYPE MIX
TN 002 0 10 06 DES SAS 1 DEC 2000
TN 016 0 10 03 KEY 00 MARP DES ROM 7 FEB 2000
(2008)
I'm looking to make a liste like:
DN TN
0
2203 008 0 09 02
2204 008 0 09 03
7906 002 0 10 06
7906 016 0 10 03
Have tried this:
Clearly, I'm in deep water here...
;-)
Can someone please help?
sample record:
DN 0
TYPE CDP
STCD TSC
DN 2203
CPND
CPND_LANG ROMAN
NAME
XPLN 27
DISPLAY_FMT FIRST,LAST
TYPE 500
TN 008 0 09 02 MARP DES SAS 17 FEB 2003
DN 2204
CPND
CPND_LANG ROMAN
NAME
XPLN 27
DISPLAY_FMT FIRST,LAST
TN 008 0 09 03 MARP DES SAS 17 FEB 2003
DN 7906
CPND
CPND_LANG ROMAN
NAME
XPLN 27
DISPLAY_FMT FIRST,LAST
TYPE MIX
TN 002 0 10 06 DES SAS 1 DEC 2000
TN 016 0 10 03 KEY 00 MARP DES ROM 7 FEB 2000
(2008)
I'm looking to make a liste like:
DN TN
0
2203 008 0 09 02
2204 008 0 09 03
7906 002 0 10 06
7906 016 0 10 03
Have tried this:
Code:
awk ' BEGIN { RS="" }
{ print "DN\tTN" ( i=1 ) }
{
while (i == 1) {
/^DN\ +/ ( dn=$2 )
/^TN\ +/ ( loop=$2 && shelf=$3 && card=$4 && unit=$5 )
printf("%d\t%d %d %d %d\n",dn,loop,shelf,card,unit);
i++
}
}' $1
Clearly, I'm in deep water here...
;-)
Can someone please help?