seperate ioscan device file names with awk ? (142 Views)
Reply
Trusted Contributor
Stuart Abramson
Posts: 278
Registered: ‎07-15-1999
Message 1 of 5 (142 Views)
Accepted Solution

seperate ioscan device file names with awk ?

I want to capture each single device file name in a variable from ioscan -fnk with awk.

ioscan varies the output to fit the window, so sometimes he has 2 columns and sometimes he has three columns, etc. I want to get all the values in 1 column.

Look what happens:

# ioscan -fnkH0/12/0/0 | grep rmt | awk 'OFS="\n"; {print $0}>
/dev/rmt/68m /dev/rmt/68mnb /dev/rmt/c39t0d2BESTn
/dev/rmt/68m /dev/rmt/68mnb /dev/rmt/c39t0d2BESTn
/dev/rmt/68mb /dev/rmt/c39t0d2BEST /dev/rmt/c39t0d2BESTnb
/dev/rmt/68mb /dev/rmt/c39t0d2BEST /dev/rmt/c39t0d2BESTnb
/dev/rmt/68mn /dev/rmt/c39t0d2BESTb
/dev/rmt/68mn /dev/rmt/c39t0d2BESTb
/dev/rmt/69m /dev/rmt/69mnb /dev/rmt/c39t0d3BESTn
/dev/rmt/69m /dev/rmt/69mnb /dev/rmt/c39t0d3BESTn
/dev/rmt/69mb /dev/rmt/c39t0d3BEST /dev/rmt/c39t0d3BESTnb
/dev/rmt/69mb /dev/rmt/c39t0d3BEST /dev/rmt/c39t0d3BESTnb

Please use plain text.
Honored Contributor
RAC_1
Posts: 5,920
Registered: ‎03-21-2002
Message 2 of 5 (142 Views)

Re: seperate ioscan device file names with awk ?

ioscan -fnkH0/12/0/0 | grep rmt | awk 'OFS="\n"; {print $0}'|tr " " "\n"

There is no substitute to HARDWORK
Please use plain text.
Trusted Contributor
Stuart Abramson
Posts: 278
Registered: ‎07-15-1999
Message 3 of 5 (142 Views)

Re: seperate ioscan device file names with awk ?

Well, that will do it, and I'll give you 10 points, but I'd like to know what's wrong with my "awk".
Please use plain text.
Valued Contributor
Rajeev Tyagi
Posts: 89
Registered: ‎11-05-2000
Message 4 of 5 (142 Views)

Re: seperate ioscan device file names with awk ?

You can also use

# ioscan -fnkH0/12/0/0 | grep rmt | awk '{printf "%s\n%s\n%s\n%s\n", $1,$2,$3,$4}'
Please use plain text.
Valued Contributor
Rajeev Tyagi
Posts: 89
Registered: ‎11-05-2000
Message 5 of 5 (142 Views)

Re: seperate ioscan device file names with awk ?

Stuart,

Here you are printing whole line with $0 variable your output field seperator OFS=\n will be applicable to new line. If you change your awk command to
ioscan -fnkH0/12/0/0 | grep rmt | awk 'OFS="\n"; {print $1,$2,$3,$4}'

OFS will work for each parameter in print command.
Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation