pipe to sed or perl, please help

I would like to extract the volume id which is associated with the location /dev/sdf

My script outputs the following:

/dev/sdf        vol-606f548d
/dev/sdb         vol-5e6c89b2
/dev/sda1      vol-046c89e8

I would like to pipe it to sed or perl to extract this ouput:


I got as far as this:

my_command | sed -n '/sdf/p'

but this gives me the whole line:
/dev/sdf      vol-606f548d

LVL 25
Kyle HamiltonData ScientistAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

what about awk?

my_command | awk '{ print $2 }'
Best use "awk":

my_command | awk '/^\/dev\/sdf/ {print $2}'

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
But if you prefer "sed":

my_command | sed -n 's@^/dev/sdf *@@p'
Kyle HamiltonData ScientistAuthor Commented:
Thank you! saved me so many hours :)
in perl, it would be:
my_command | perl -ne 'if (m{^/dev/sdf\s+(\S+)}) { print $1 }'

Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux OS Dev

From novice to tech pro — start learning today.