Naveen Kumaar
Naveen Kumaar

Reputation: 11

Demangle all c++ symbols in a txt file using SED, ECHO and C++FILT

Consider an input file that has the below content:

RANDOM CONTENTS1
FN:4,_Z1fv
FN:5,_Z1gv
RANDOM CONTENTS2

Need to search for the mangled symbols in the input txt file and replace them with their demangled names, and print it as output like below:

RANDOM CONTENTS1
FN:4,f()
FN:5,g()
RANDOM CONTENTS2

It is given that, there is no other line that will have a comma followed by underscore. So, I can use a ",(_.*)" to capture the mangled symbol in the input.txt file.

When I use the below command in tcsh shell, it didn't work. The output is still same as input.txt. I am unable to reason out why.

sed "s#,\(_.*\)#,`echo \\1 | /usr/bin/c++filt`#" input.txt

What is wrong with the command?

Upvotes: 0

Views: 518

Answers (2)

small ant
small ant

Reputation: 1

run this in your shell

C++filt<input.txt>input_demangle.txt

Upvotes: 0

justrajdeep
justrajdeep

Reputation: 913

I think it can be done more easily using perl

perl -i.bak -pe 'chomp($_ = qx{echo \"$_\" | /usr/bin/c++filt}) if /,_/' input.txt

Upvotes: 0

Related Questions