Script for parsing vertical log into horizontal

Hi,

I have log like this :

And i want the output like below :

I have try using awk but doesn't work

awk '
/ffff /{ts=$1}
f && /SectorAntenna\=1/{sa1=$3}
f && /SectorAntenna\=2/{sa2=$3}
f && /SectorAntenna\=3/{sa3=$3}
{
  s= ts "|" sa1 "|" sa2 "|" sa3
  print s
  f=0
}'

Anybody can help me

awk '!/QUIT/ { if($0=="Bye") { print "\n"; } else if ($0 ~ /SectorAntenna/) { printf "%d ", $2; } else { printf "%s ", $1; } } ' filename

Hi

awk '/^[0-9]/{if (x) print x;x=$1}/Sector/{x=x FS $2}END{print x}' file

Guru.

How about:

awk 'NR>1{print $1,$4,$6,$8}' RS="QUIT q\n"
1 Like

Nice solution. :slight_smile:
Id like to explain it some.

RS="QUIT q\n" This sets the record selector to QUIT q\n instead of normal new line \n .
Since this file starts with QUIT q\n , we need to suppress the first output or it will be blank. This is done with skipping record #1 by saying that it must be greater than 1 NR>1 before printing anything.
Then print field $1,$4,$6,$8
$1 first field after QUIT q\n
$4 field after SectorAntenna=1
$6 field after SectorAntenna=2
$8 field after SectorAntenna=3
Buy is not printed since its on an odd field number and not field #1

1 Like

or sed

sed -n '/QUIT/d;:i;/^[0-9]/s! .*!!g;/[0-9]$/s!.* !!g;/Bye/!{H;n;bi};s!Bye.*!!g;x;s!\n! !g;s!^ !!g;p' infile

Very nice and creative proposals indeed!
Anyhow, the requestor's solution can be slightly adapted/pruned and will work also (pls note that he seems to want a pipe symbol separator):

awk '/ffff/ {ts=$1}
     /SectorAntenna/ {ts=ts"|"$2}
     /Bye/ {print ts; ts="" }
    ' file
00285_BKU_KTQEL|30|30|0
02415_BKU_ERDAL|60|60|60
00070_BKU_KTIZM|60|60|60
00190_BKU_METBU|90|100|80
00083_AGU_AGSUS
00395_CEL_ALLAR
00079_MAS_MASAL|60|50|50
00100_BAB_BABEK
00803_BIL_BILES

Thanks all for the solution. It's helpful