Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
Languages and Scripting
cancel
Showing results for 
Search instead for 
Did you mean: 

seperate ioscan device file names with awk ?

SOLVED
Go to solution
Highlighted
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
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.