Dallas Dallas - 1 year ago 90
Linux Question

How to extract particular string from a file (linux)

I have the following file

vol-12345678 gp2
VOLUMES 2016-03-17T22:03:08.374Z False 100 16 snap-7073d522 in-use vol-4568gds4 gp2
ATTACHMENTS 2016-03-17T22:03:08.000Z True /dev/sda1 i-181ed33c attached vol-7ea1c83f



I want to extract all instances of 'vol-********' and output it to a file (without the other contents) resulting in a file of:





This is a relatively small file so I could do it manually, but I have another file with 200+ cases. Any idea how to use this using GREP or SED or AWK? Thanks!

agc agc
Answer Source

This should do it:

grep -o 'vol-[[:alnum:]]*' input.data > output.data
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download