Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get next line

Status
Not open for further replies.

frangac

Technical User
Feb 8, 2004
163
ZA
Hi All,

On my prevoius post I tried to align 3 lines into one, (thanks to PHV) some success. What I am now trying to achive is to , once /DSB/ is found , define what I need from that line ,and then read the next line which starts with +++=, and define $2 then once all defining is done use the printf statement.

My Script
/tools/Chris filename |
awk '{
Here is no problem ---- > if(match($1,"BIL=")){
for (e=1;e<NF;e++){if ($e~/^BIL/){
LA=$(e+4)
{if ($(e+4)==00){
Anum="NULL"
}else{
A_num=$(e+5)
}}}
if($e~/P=65/){
BNUM=$(e+2)
LN=$(e+1)
}
if($e~/P=64/){
DATE=$(e+1)
DUR=$(e+3)
}
if($e~/P=67/){
UN=$(e+1)
}}
hexstr="0123456789abcdef"
newnum=tolower(substr(DUR,5,2) substr(DUR,3,2) substr(DUR,1,2))
YEAR=tolower(substr(DATE,1,2))
MONT=tolower(substr(DATE,3,2))
DAY=tolower(substr(DATE,5,2))
HOUR=tolower(substr(DATE,7,2))
MIN=tolower(substr(DATE,9,2))
SEC=tolower(substr(DATE,11,2))
OPE=tolower(substr(UN,5,2) substr(UN,3,2) substr(UN,1,2))
LEN=tolower(substr(LN,1,2))
ALEN=tolower(substr(LA,1,2))
AN=tolower(substr(Anum,1,15))
decnum12 = 0

slen_bn = length(LEN)
#do some stuff here ---------->
}
printf ("%11s %.2d-%.2d-%.2d %.2d:%.2d:%.2d %18s %10d (%d)\n",AN,decnum6,decnum5,decn
um1,decnum2,decnum3,decnum4,BN,decnum,decnum7)
}
}
}else{
Here is no problem ---- > if(match($1,"DSB=")){
hexstr="0123456789abcdef"
newnum=tolower(substr($9,3,2) substr($9,1,2))
YEAR=tolower(substr($10,1,2))
MONT=tolower(substr($10,3,2))
DAY=tolower(substr($10,5,2))
HOUR=tolower(substr($10,7,2))
MIN=tolower(substr($10,9,2))
SEC=tolower(substr($10,11,2))
LEN=tolower(substr($11,1,2))
ALEN=tolower(substr($6,1,2))
AN=tolower(substr($7,1,15))
slen = length(newnum)
slen1 = length(MONT)
slen2 = length(DAY)
slen3 = length(HOUR)
slen4 = length(MIN)
slen5 = length(SEC)
slen6 = length(YEAR)
slen7 = length(OPE)
# Here is where I get stuck
once next line is read, define
OPE=tolower(substr($2,21,2) substr($2,19,2))
slen7 = length(OPE)

decnum7 = 0
for (i=1;i<slen7+1;i++)
{
tposOP = index(hexstr,substr(OPE,i,1))-1
decnum7=decnum7+((16**(slen7 -i))*tposOP)
}
}
printf ("%11s %.2d-%.2d-%.2d %.2d:%.2d:%.2d %18s %10d (%d)\n",AN,decnum6,decnum5,decn
um1,decnum2,decnum3,decnum4,BN,decnum,decnum7)
}}}'

A sample of the record is

DSB=fb 00 80 00 01 0a 021941930000 0000 2a00 040907111d1c 0a 015306200000000000
+++= 00000010002c000000ca1f000102ac026000ad0416001500064a474448414298
+++= 020b
+++= 5050524841426400aa03041023ab08454e5155495232201702fc09ca1f00000000000000bc7f1e4f481f00000017bb40f530000052d2bb40f530433e0dda

Many Thanks
Chris
 
I haven't taken the time to figure out your logic, but would a

getline

at the problem area solve your problem?

CaKiwi
 
Hi CaKiwi,

Thanks for your response.

I did try getline at this point like so :
slen2 = length(DAY)
slen3 = length(HOUR)
slen4 = length(MIN)
slen5 = length(SEC)
slen6 = length(YEAR)
slen7 = length(OPE)

decnum4 = 0
for (i=1;i<slen3+1;i++)
{
tposS = index(hexstr,substr(SEC,i,1))-1
decnum4=decnum4+((16**(slen5 -i))*tposS)
}
# Here is where I get stuck
getline
{if($1~/\+++/){
OPE=tolower(substr($2,21,2) substr($2,19,2))
slen7 = length(OPE)
}
}
decnum7 = 0
for (i=1;i<slen7+1;i++)
{
tposOP = index(hexstr,substr(OPE,i,1))-1
decnum7=decnum7+((16**(slen7 -i))*tposOP)
}
}
}
printf ("%11s %.2d-%.2d-%.2d %.2d:%.2d:%.2d %18s %10d (%d)\n",AN,decnum6,decnum5,decnum1,decnum2,decnum3,decnum4,BN,decnum,decnum7)
}
}'

and the results were duplicated. Is the getline in its right position ??

012345678 2004-09-07 20:00:20 0234567890 0 2
012345678 2004-09-07 20:00:20 0234567890 2 (0)

My explanation on this script

I convert a filename from binary to hex format (/tools/Chris/) and then I call awk to read the file. If the $1 of the record starts with /BIL/, define whatever fields are required and then printf
Read the next line and if $1 ~/DSB/ do the same. With /DSB/ records it contains 3 lines which is = to 1 record were as BIL is a single line. The second line of the /DSB/ (substr($2,21,2) substr($2,19,2))
is required so that I use it in my printf statement ( (%d) )

If there is a better or simple way to do this I will very much appreciate it

Thanks
Chris
 
CaKiwi,

I solved my problem. It was a "}" in the wrong position, that's why is was duplicating but the getline does work.

Anyway I asked the question if there is a easier way to do this and if so could you please explain (with script if possible).

Many Thanks Once Again
Chris


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top