Issue
I have the following file
vol-12345678 gp2
vol-89dfg58g
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
etc.
etc.
I want to extract all instances of 'vol-********' and output it to a file (without the other contents) resulting in a file of:
vol-12345678
vol-34556767
vol-34534sdf
...
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!
Solution
UPDATE Command:
sed -n 's/.*\b\(vol-[[:alnum:]]*\).*/\1/'p test2
Output:
vol-12345678
vol-89dfg58g
vol-4568gds4
vol-7ea1c83f
Flags: n : Suppress automatic printing of pattern space. p : Print out the pattern space
Pattern:
- Look for 'vol-[alphanumeric]s'
- Substitute it and print the first match with \1
More details Sed
Answered By - Avikd