Operating System - HP-UX
1827807 Members
2614 Online
109969 Solutions
New Discussion

Process multi-line input w/awk?

 
SOLVED
Go to solution
Pete Randall
Outstanding Contributor

Process multi-line input w/awk?

I'm trying to process ioscan -fn output through awk, combining the two lines of output into a single line of selected information as in the attached example.

Pete
9 REPLIES 9
Thierry Poels_1
Honored Contributor

Re: Process multi-line input w/awk?

Hi,

the following will join the lines:

ed ioscan.tmp << [EOT]
,g/^disk/.,.+1j
w
q
[EOT]


formatting output afterwards should be piece of cake ;)

good luck,
Thierry.
All unix flavours are exactly the same . . . . . . . . . . for end users anyway.
harry d brown jr
Honored Contributor

Re: Process multi-line input w/awk?

Use getline:

http://www.cs.ruu.nl/docs/vakken/st/nawk/nawk_25.html#SEC28

live free or die
harry
Live Free or Die
James R. Ferguson
Acclaimed Contributor

Re: Process multi-line input w/awk?

Hi Pete:

You could do something like this:

# ioscan -kfnC disk|awk 'A=$1;B=$3;C=$7;D=$8;getline;E=$1;F=$2;print A,B,C,D,E,F}'

Regards!

...JRF...
harry d brown jr
Honored Contributor

Re: Process multi-line input w/awk?

Why don't you just add the


-F (note upper case) to ioscan

the output looks like this:

scsi:wsio:T:T:F:31:188:4096:disk:sdisk:0/0/1/0.1.0:5 128 2 2 0 0 0 0 90 114 96 2
55 0 0 0 0 :2:root.sba.lba.c720.tgt.sdisk:sdisk:CLAIMED:DEVICE:HP DVD-ROM 3
05:0
/dev/dsk/c0t1d0 /dev/rdsk/c0t1d0

then just use the awk command -F:

live free or die
harry
Live Free or Die
Robin Wakefield
Honored Contributor
Solution

Re: Process multi-line input w/awk?

Hi Pete,

This should work for all devices, not just disks:

======================================
#!/bin/ksh

ioscan -fn|
awk '/^Class/{printf ("%-10s%-4s%-8s%-30sDevice File\n",$1,$3,$4,$NF)}
/^\=/{printf("%s",$0)}
/CLAIMED/{printf ("\n%-10s%-12s",$1,$3);
DESC="";for (i=7;i<=NF;i++){DESC=DESC" "$i};
printf("%-30s",DESC)}
/dev/{printf("%-20s",$1)}
END{print}'
=========================================

Rgds, Robin.
harry d brown jr
Honored Contributor

Re: Process multi-line input w/awk?

Your ioscan will have to look like this:

ioscan -C disk -kfnF | awk -F: 'scripthere'


live free or die
harry
Live Free or Die
Pete Randall
Outstanding Contributor

Re: Process multi-line input w/awk?

Thanks to all of you. Being a lazy son of a gun, I like JRF's answer the most but all would appear to work just fine. Thanks again.

Pete
Pete Randall
Outstanding Contributor

Re: Process multi-line input w/awk?

That is, I liked JRF's answer the best until I read Robin's.

Pete
James R. Ferguson
Acclaimed Contributor

Re: Process multi-line input w/awk?

Hi Pete:

I *knew* Robin would have the best answer if he were reading this! ;-)

Regards!

...JRF...