[Insight-users] bash script to search example files for terms

Darren Weber darren.weber.lists at gmail.com
Mon Oct 12 14:15:26 EDT 2009


This is a short bash script (grep does the work) to search for terms in the
InsightToolkit example files.  It's a convenience wrapper that stores the
path to the example files (.cxx in this case), the syntax of the grep call,
and allows multiple terms to be given at once.  Modify the example search
path for your purposes (it could be modified to search for the tcl or python
examples too).  Modify the grep call as you like.

#### BEGIN SCRIPT
#!/bin/bash

if [ $# -lt 1 ]; then
    echo "$0 'search term' ['search term' ...]"
    exit 1
fi

# Search the CXX files
itkExamplePath="/opt/local/share/InsightToolkit/examples/*/*.cxx"
echo "Searching ITK .cxx files in: ${itkExamplePath}"

for term in $@; do
    echo
    echo "Search term: ${term}"
    grep -l -E -e ${term} ${itkExamplePath}
done
#### END SCRIPT

This is an example call on my platform:

$ itkSearchExamples.bash 'TransformWriter' 'TransformReader'
Searching ITK .cxx files in:
/opt/local/share/InsightToolkit/examples/*/*.cxx

Search term: TransformWriter
/opt/local/share/InsightToolkit/examples/IO/TransformReadWrite.cxx

Search term: TransformReader
/opt/local/share/InsightToolkit/examples/IO/TransformReadWrite.cxx
/opt/local/share/InsightToolkit/examples/Registration/DeformableRegistration14.cxx
/opt/local/share/InsightToolkit/examples/Registration/DeformableRegistration8.cxx

Take care,
Darren
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20091012/13888bb6/attachment-0001.htm>


More information about the Insight-users mailing list