BladeSystem Forums have moved here
To make BladeSystem information easier to find, we have moved the BladeSystem forums here, to Servers and Operating Systems.
Languages and Scripting
Showing results for 
Search instead for 
Do you mean 

seperate ioscan device file names with awk ?

SOLVED
Go to Solution
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
Honored Contributor

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
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".
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}'
Highlighted
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.