Operating System - HP-UX
1752803 Members
5324 Online
108789 Solutions
New Discussion юеВ

seperate ioscan device file names with awk ?

 
SOLVED
Go to solution
Stuart Abramson
Trusted Contributor

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

4 REPLIES 4
RAC_1
Honored Contributor
Solution

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
Stuart Abramson
Trusted Contributor

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".
Rajeev Tyagi
Valued Contributor

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}'
Rajeev Tyagi
Valued Contributor

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.