Skip to content

Instantly share code, notes, and snippets.

@cls cls/nmgrep.sh
Last active Jun 1, 2018

Embed
What would you like to do?
Script to grep objects' symbol tables
#!/bin/sh
pattern="$1"
shift
if [ $# -gt 1 ]
then
GREP_OPTIONS="$GREP_OPTIONS --with-filename"
export GREP_OPTIONS
fi
for file in "$@"
do
nm -P "$file" | awk '{print $2,$1}' | c++filt | grep --label="$file" --regexp="$pattern"
done
@cls

This comment has been minimized.

Copy link
Owner Author

cls commented Jan 31, 2017

This script requires GNU grep, and an optional C++ demangler, but is otherwise POSIX compatible.

The GNU dependency can be removed by doing something like the following.

nm -P "$file" | awk '{print $2,$1}' | c++filt | grep "$pattern" | while read match
do
	printf '%s:%s\n' "$file" "$match"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.