awk
is a pattern matching language. The grep
is totally unnecessary.
awk '/bar/{print $3}' foot.txt
does what your example does.
Edit Fixed up a bit after reading the comments on the precedeing answer (I don't know a thing about dem
...):
You can make use of the system
call in awk with something like:
awk '/bar/{cline="dem " $3; system(cline)}' foot.txt
but this would spawn an instance of dem
for each symbol processed. Very inefficient.
So lets get more clever:
awk '/bar/{list = list " " $3;}END{cline="dem " list; system(cline)}' foot.txt
BTW-- Untested as I don't have dem
or your input.
Another thought: if you're going to use the xargs
formulation offered by other posters, cut
might well be more efficient than awk
. At that point, however, you would need grep
again.