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

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


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.




>
>
>    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
> >> >
> >> >
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20091012/81973bca/attachment-0001.htm>


More information about the Insight-users mailing list