tags:

views:

615

answers:

3

Hi all,

Here is a query:

grep bar 'foo.txt' | awk '{print $3}'

The field name emitted by the 'awk' query are mangled C++ symbol names. I want to pass each to dem and finally output the output of 'dem'- i.e the demangled symbols.

Assume that the field separator is a ' ' (space).

+1  A: 

How about

grep bar 'foo.txt' | awk '{ print $3 }' | xargs dem | awk '{ print $3 }'
David Zaslavsky
The way I read the dem man page, the symbol names should be on the command line rather than stdin
Charles Duffy
oops, I misread that. I edited in a call to xargs which should fix it.
David Zaslavsky
well, the c++ side could have spaces in them :)
Johannes Schaub - litb
darn, I was hoping that wouldn't be the case...
David Zaslavsky
yeah my c++filt stuff won't work with his (apparently) Sun mangling style :/. but you may lucky maybe dem doesn't put spaces into the c++ side? from what the examples show, it omits showing the return type, at least
Johannes Schaub - litb
+3  A: 

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.

dmckee
+1  A: 

This will print the demangled symbols, complete with argument lists in the case of methods:

awk '/bar/ { print $3 }' foo.txt | xargs dem | sed -e 's:.* == ::'

This will print the demangled symbols, without argument lists in the case of methods:

awk '/bar/ { print $3 }' foo.txt | xargs dem | sed -e 's:.* == \([^(]*\).*:\1:'

Cheers, V.

vladr