Quote:
Originally Posted by sysmicuser
All I want is the resource name which comes as First word AFTER Volume.
|
If the data is guaranteed well-formed, there's no need for a test - either of these would do:
Code:
awk '{print $7}' extract_data.txt
Code:
cut -d' ' -f7 extract_data.txt
Otherwise, I might use slight variations on the various examples already provided...
If you need to exclude certain rows, you can say when column 6 is "Volume", print column 7 - this is more restrictive than just checking Volume exists within the line:
Code:
awk '$6=="Volume" {print $7}' extract_data.txt
If "Volume" is at an unknown/changing position, a tweaked version of the answer Grail provided:
Code:
awk -vRS='\\s' 'found {print;found=0} /\<Volume\>/ {found=1}' extract_data.txt
Mainly the "\<" and "\>" ensure "Volume" is a distinct word and fixing the variable to make it obvious what "found" is doing.
Using "\s" for the record separator provides more predictable behaviour at end of lines (though not necessarily correct).
Turbocapitalist's Perl also may need a word boundary at the start, and can use "$&" instead of the capturing group.
Code:
perl -n -e 'm/(?<=\bVolume )\S+/ && print $&,"\n"' extract_data.txt
Also, because it's Perl there's a slightly simpler version available, using "\K" to reset the match text, but not the position instead of the lookbehind.
Code:
perl -n -e 'm/\bVolume \K\S+/ && print $&,"\n"' extract_data.txt
And whilst Perl is very powerful, we don't need all that power here, and can just use grep with -P flag:
Code:
grep -oP '\bVolume \K\S+' extract_data.txt