Read the apecific data from one file and write into another file

Hi, I would like to read the specific data from file and write the data in the new file.

My data input is something like this..

<EXROP:R=TJ0311T;
ROUTE DATA
R        ROUTE PARAMETERS
TJ0311T  DETY=UPDR     TTRANS=1   FNC=3      
         MA=628160955000      
         R=TJ0311D
         ST=7       SI=ISUP4    SP=2-1021   

         GENERIC PARAMETERS IN ROUTE OWNER
         MGG=ISUP51

END


R        ROUTE PARAMETERS
TJ0312T  DETY=UPDR     TTRANS=1   FNC=3      
         MA=628160955000      
         R=TJ0311D
         ST=7       SI=ISUP4    SP=2-1022   

         GENERIC PARAMETERS IN ROUTE OWNER
         MGG=ISUP52

END

Expected output should be....

TJ0311T  DETY=UPDR  SP=2-1021  MGG=ISUP51
TJ0312T  DETY=UPDR  SP=2-1022  MGG=ISUP52

Kindly help to write a script..
Thanks in advance.

Try:

awk '/DETY/ { s=""; s=$1" "$2; } /SP=/ {s=s" "$3; } /MGG=/ { s=s" "$1; } /END/ { print s; }' file
1 Like
/usr/xpg4/bin/awk 'BEGIN {t1="";t2="";t3="";t4="";}
{ if ($1 ~ /TJ/ && $2 ~ /DETY/ ) { t1=$1; t2=$2; next; } }
{ if ($3 ~ /SP/) { t3=$3; next;  } }
{ if($1 ~ /MGG/) { t4=$1; next;  } }
{ if($1 ~ /END/) { print t1,t2,t3,t4}}
' file1

Hi, Thanks a lot.. it works great...