I want to print the matched pattern using awk. Not the field, not the line.
In vi, you can put the matched pattern in the substitution by surrounding it with parens and referencing it with curly braces and a number, like this:
:s/bufid=([0-9]*)/buffer id is {\0}/
The part that matches between parens is remembered and can be used.
In perl, it is similar
$_ = "Hello there, neighbor";
if (/\s(\w+),/) { # memorize the word between space and comma
print "the word was $1\n"; # the word was there
}
Is there any way I can do something similar with awk? I just want to extract the buffer id and print it, and only it.
The input line is XML, and will contain (among other things) 'bufId="123456"'. I want to print "123456"
so ...
awk < file.xml '/bufId="([0-9]*)"/ { print X; }'
What do I put where X is?
Can this even be done?