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

Andrew Maclean andrew.amaclean at gmail.com
Mon Oct 12 22:50:16 EDT 2009


Could this script with appropriate modifications also be added to VTK?
It strikes me as useful.

Rgeards
  Andrew


On Tue, Oct 13, 2009 at 12: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
>
> ---
>
> The second script,
> are you suggesting it as a separate script ?
> or as an improvement to the first one ?
>
>
>    Please let us know,
>
>
>          Thanks
>
>
>                Luis
>
>
> ----------------------------
> On Mon, Oct 12, 2009 at 4:15 PM, Darren Weber
> <darren.weber.lists at gmail.com> wrote:
>>
>> Hi Luis,
>>
>> Please feel free to distribute it with the LGPL license (or a BSD license,
>> or something that is compatible with the ITK license and general OSI
>> principles).
>>
>> For a more portable solution, the itk*Path variables might be obtained
>> automatically (how?).  The search path could be an input parameter (but that
>> almost defeats the convenience of this bash wrapper around a grep process).
>>
>> The grep command options list the files where the search term is found (not
>> the lines of those files where the search term occurs).  For a bit more
>> value, it's possible to modify the script so that the entire grep loop
>> returns an array of file paths, which could be piped into something like:
>> less -p ${searchTerm} ${fileArray}[@]
>> Then less would provide the means to page through the files.
>>
>> Here is another variation on the same thing - this one searches the testing
>> path and it includes the .tcl and .py example files in the search.  It might
>> be called 'itkSearchFiles.bash' ?
>>
>> ###### 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/Code"
>>
>> 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}"
>>         grep -l -E -e ${term} ${itkPath}/*/*.cxx
>>         grep -l -E -e ${term} ${itkPath}/*/*.tcl
>>         grep -l -E -e ${term} ${itkPath}/*/*.py
>>     done
>> done
>> ###### END SCRIPT
>>
>>
>> Take care,
>> Darren
>>
>>
>>
>>
>>
>>
>> On Mon, Oct 12, 2009 at 12:26 PM, Luis Ibanez <luis.ibanez at kitware.com>
>> wrote:
>>>
>>> Hi Darren,
>>>
>>> This is really useful !
>>>
>>> Thank you for sharing it.
>>>
>>> Do you see any reason for not adding this to the CVS
>>> repository and distribute it along with ITK ?
>>>
>>> Please let us know,
>>>
>>>
>>>    Thanks
>>>
>>>
>>>          Luis
>>>
>>>
>>> ---------------------------------------
>>> On Mon, Oct 12, 2009 at 2:15 PM, Darren Weber
>>> <darren.weber.lists at gmail.com> wrote:
>>> >
>>> > 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
>>> >
>>> >
>>> > _____________________________________
>>> > Powered by www.kitware.com
>>> >
>>> > Visit other Kitware open-source projects at
>>> > http://www.kitware.com/opensource/opensource.html
>>> >
>>> > Please keep messages on-topic and check the ITK FAQ at:
>>> > http://www.itk.org/Wiki/ITK_FAQ
>>> >
>>> > Follow this link to subscribe/unsubscribe:
>>> > http://www.itk.org/mailman/listinfo/insight-users
>>> >
>>> >
>>
>>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the ITK FAQ at: http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
>



-- 
___________________________________________
Andrew J. P. Maclean
Centre for Autonomous Systems
The Rose Street Building J04
The University of Sydney  2006  NSW
AUSTRALIA
Ph: +61 2 9351 3283
Fax: +61 2 9351 7474
URL: http://www.acfr.usyd.edu.au/
___________________________________________


More information about the Insight-users mailing list