Is all the output in one file, or do you get these outputs from two different places?
A regular expression is just a piece of text, there are a few special characters which make it a lot more versatile than just wildcards but just try putting the text you want to look for between a pair of slashes. Then in the print part you probably just want one or two fields at predictable places. That's $1 for the first word of output on the matching line, $2 for the second, etc.
awk '/^add map / { print $3, $8 }'
(The ^ is one of those magical characters; it anchors this to beginning of line.)
But is there a way to rip the text out with out knowing the positions of the text ?
Allso sometimes there would be multiple instances og the field on the same line and i would like to catch them all.
That's perfectly understandable. In Awk Classic I guess you would simply run match() on all lines to grab the match; gawk and friends might have a way to figure out what matched in the condition.
In sed the traditional solution would be to replace everything before and after the sought regular expression with an empty string; certainly you could do that in awk too.
Seems i found a viable solution, thought i post it here.
I have now played a bit with awk and come to a solution.
Content of text.txt :
add map loop0p1 : 0 208782 linear /dev/loop0 63
add map loop0p2 : 0 20755980 linear /dev/loop0 208845
Reading all physical volumes. This may take a while...
Found volume group "VolGroup00" using metadata type lvm2
#First we match /VolGroup[0-9]/ against file and return matching line to $0 #Then we use the match expression to match the VolGroup regexp and find char start and length #Now we print out the substring of $0 with the start char and length.