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

Darren Weber darren.weber.lists at gmail.com
Mon Oct 12 23:31:18 EDT 2009


On Mon, Oct 12, 2009 at 8:09 PM, Darren Weber
<darren.weber.lists at gmail.com>wrote:

>
>
> On Mon, Oct 12, 2009 at 6:40 PM, Luis Ibanez <luis.ibanez at kitware.com>wrote:
>
>> Hi Darren,
>>
>> Thanks for the script.
>>
>> It has now been committed to the CVS repository as
>>
>>         Insight/Examples/SearchScript.sh
>>
>>
> OK ;-)
>
>
>
>> ---
>>
>> The second script,
>> are you suggesting it as a separate script ?
>> or as an improvement to the first one ?
>>
>
>
> I guess it's an improvement, as I prefer the second script, but anyone
> doing only .cxx work might prefer not to see any .tcl or .py files returned.
>
>

This may be another improvement, using 'find' to get a list of all the files
to search.


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

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

itkExamplePath="/opt/local/share/InsightToolkit/examples"
itkTestingPath="/opt/local/share/InsightToolkit/testing"

for term in $@; do
    echo
    echo "Search term: ${term}"
    for itkPath in "${itkExamplePath}" "${itkTestingPath}" ; do
        if [ ! -d ${itkPath} ]; then
            echo "Path not found: ${itkPath}"
        fi
        echo "Searching ITK files in: ${itkPath}"
        cxxFiles=$(find ${itkPath} -name "*.cxx")
        grep -l -E -e ${term} ${cxxFiles}
        tclFiles=$(find ${itkPath} -name "*.tcl")
        grep -l -E -e ${term} ${tclFiles}
        pyFiles=$(find ${itkPath} -name "*.py")
        grep -l -E -e ${term} ${pyFiles}
    done
done
#######END SCRIPT
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20091012/b09a3f7a/attachment.htm>


More information about the Insight-users mailing list