Operating System - HP-UX
1838580 Members
3029 Online
110128 Solutions
New Discussion

Re: Newbie grep question...

 
SOLVED
Go to solution
Gene Laoyan
Super Advisor

Newbie grep question...

Here's my commandline...
ioscan -fnC disk | grep '/dev/rdsk/c7t0d1'

It returns the following...
/dev/dsk/c7t0d1 /dev/dsk/c7t0d1s2 /dev/rdsk/c7t0d1 /dev/rdsk/c7t0d1s2
/dev/dsk/c7t0d1s1 /dev/dsk/c7t0d1s3 /dev/rdsk/c7t0d1s1 /dev/rdsk/c7t0d1s3

I only want the first line, how do I do that?

If I want only the second line, how do I do that?

Thanks
6 REPLIES 6
Geoff Wild
Honored Contributor
Solution

Re: Newbie grep question...

ioscan -fnC disk | grep '/dev/rdsk/c7t0d1' |head -1

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Victor BERRIDGE
Honored Contributor

Re: Newbie grep question...

And for the last line:
ioscan -fnC disk | grep '/dev/rdsk/c7t0d1' |tail -1


All the best
Victor
Ivan Krastev
Honored Contributor

Re: Newbie grep question...

If you want only 1st line use head:

ioscan -fnC disk | grep '/dev/rdsk/c7t0d1' | head -n1


regards,
ivan
Pete Randall
Outstanding Contributor

Re: Newbie grep question...

Or, for the second line,

ioscan -fnC disk | grep '/dev/rdsk/c7t0d1' |head -2 |tail -1


Pete

Pete
Jonathan Fife
Honored Contributor

Re: Newbie grep question...

If you only want grep to return a line with the exact pattern you specified and no leading or trailing non-white characters you can use the -w argument.

ioscan -fnC disk | grep -w '/dev/rdsk/c7t0d1'

Your second question is a bit trickier. What would be your criteria for returning only the second line? The fact that it is second? The fact that it doesn't include the /dev/rdsk/c7t0d1 string except with additional characters at the end? The fact that it includes s1 and s3 and not s2?

Decay is inherent in all compounded things. Strive on with diligence
Gene Laoyan
Super Advisor

Re: Newbie grep question...

Points awarded!
Thanks everyone!!!