Link to home
Start Free TrialLog in
Avatar of Kyle Hamilton
Kyle HamiltonFlag for United States of America

asked on

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:

vol-606f548d

I got as far as this:

my_command | sed -n '/sdf/p'

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

Thanks,
Kyle
Avatar of benhanson
benhanson

what about awk?

my_command | awk '{ print $2 }'
ASKER CERTIFIED SOLUTION
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
But if you prefer "sed":

my_command | sed -n 's@^/dev/sdf *@@p'
Avatar of Kyle Hamilton

ASKER

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