<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Need help with a script in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/need-help-with-a-script/m-p/4036747#M93963</link>
    <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;Ooops; a slight correction to retain the order of matched lines while still sorting the filenames output:&lt;BR /&gt;&lt;BR /&gt;# perl -MFile::Find -e 'find(sub{push @f,$File::Find::name if -f $_ &amp;amp;&amp;amp; -T _},".");@a=sort @a;@a=`grep -i $ARGV[0] @f`;print @a' string_to_match&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
    <pubDate>Fri, 13 Jul 2007 08:40:44 GMT</pubDate>
    <dc:creator>James R. Ferguson</dc:creator>
    <dc:date>2007-07-13T08:40:44Z</dc:date>
    <item>
      <title>Need help with a script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/need-help-with-a-script/m-p/4036744#M93960</link>
      <description>I need a script that search only text files for any occurrence for a certain word, and then will send the following information to a separate log file: the full path of the file.&lt;BR /&gt;&lt;BR /&gt;could anyone help?</description>
      <pubDate>Thu, 12 Jul 2007 16:57:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/need-help-with-a-script/m-p/4036744#M93960</guid>
      <dc:creator>S-un-B-ix-S</dc:creator>
      <dc:date>2007-07-12T16:57:00Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with a script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/need-help-with-a-script/m-p/4036745#M93961</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;Here's a Perl script that recursively finds all *text* (not binary) files in the current directory and reports case-insensitive matches to the pattern passed as an argument &lt;STRING_TO_MATCH&gt;:&lt;BR /&gt;&lt;BR /&gt;# perl -MFile::Find -we 'find(sub{push @f,$File::Find::name if -f $_ &amp;amp;&amp;amp; -T _},".");@a=`grep -i $ARGV[0] @f`;print for sort @a' &lt;STRING_TO_MATCH&gt;&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;/STRING_TO_MATCH&gt;&lt;/STRING_TO_MATCH&gt;</description>
      <pubDate>Thu, 12 Jul 2007 17:18:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/need-help-with-a-script/m-p/4036745#M93961</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-07-12T17:18:09Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with a script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/need-help-with-a-script/m-p/4036746#M93962</link>
      <description>Something like this should be close:&lt;BR /&gt;------------------------------------&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;&lt;BR /&gt;typeset PROG=${0}&lt;BR /&gt;if [[ ${#} -lt 1 ]]&lt;BR /&gt;  then&lt;BR /&gt;    echo "Usage: ${PROG} target_string" &amp;gt;&amp;amp;2&lt;BR /&gt;    exit 255&lt;BR /&gt;  fi&lt;BR /&gt;typeset TARGET=${1}&lt;BR /&gt;shift&lt;BR /&gt;&lt;BR /&gt;typeset FNAME=""&lt;BR /&gt;typeset -i GSTAT=0&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;find . -type f -print | while read FNAME&lt;BR /&gt;  do&lt;BR /&gt;     file "${FNAME}" | grep -q -i "ascii"&lt;BR /&gt;     GSTAT=${?}&lt;BR /&gt;     if [[ ${GSTAT} -eq 0 ]]&lt;BR /&gt;       then # it's a text file&lt;BR /&gt;         grep -q "${TARGET}" "${FNAME}"&lt;BR /&gt;         GSTAT=${?}&lt;BR /&gt;         if [[ ${GSTAT} -eq 0 ]]&lt;BR /&gt;           then&lt;BR /&gt;             echo "${NAME}"&lt;BR /&gt;           fi&lt;BR /&gt;       fi&lt;BR /&gt;  done&lt;BR /&gt;exit 0&lt;BR /&gt;-------------------------------&lt;BR /&gt;&lt;BR /&gt;Use it like this:&lt;BR /&gt;&lt;BR /&gt;cd to desired starting directory&lt;BR /&gt;findit.sh "my target string" &amp;gt; mylist&lt;BR /&gt;&lt;BR /&gt;It leverages the file command which includes "ascii" in its output of anything that is a text file. Those files are then examined with grep (-q -- quiet; we only care if a terget string is found or not; if found grep sets its exit code to 0).&lt;BR /&gt;&lt;BR /&gt;Another aproach would be to use Perl's Find::File module and use the -T test to determine if a file is a text file.&lt;BR /&gt;</description>
      <pubDate>Thu, 12 Jul 2007 17:21:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/need-help-with-a-script/m-p/4036746#M93962</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2007-07-12T17:21:38Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with a script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/need-help-with-a-script/m-p/4036747#M93963</link>
      <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;Ooops; a slight correction to retain the order of matched lines while still sorting the filenames output:&lt;BR /&gt;&lt;BR /&gt;# perl -MFile::Find -e 'find(sub{push @f,$File::Find::name if -f $_ &amp;amp;&amp;amp; -T _},".");@a=sort @a;@a=`grep -i $ARGV[0] @f`;print @a' string_to_match&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Fri, 13 Jul 2007 08:40:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/need-help-with-a-script/m-p/4036747#M93963</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-07-13T08:40:44Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with a script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/need-help-with-a-script/m-p/4036748#M93964</link>
      <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;CRIPES!&lt;BR /&gt;&lt;BR /&gt;... @f=sort @f ...&lt;BR /&gt;&lt;BR /&gt;This is the REAL correction to retain the order of matched lines while still sorting the filenames output:&lt;BR /&gt;&lt;BR /&gt;# perl -MFile::Find -e 'find(sub{push @f,$File::Find::name if -f $_ &amp;amp;&amp;amp; -T _},".");@f=sort @f;@a=`grep -i $ARGV[0] @f`;print @a' string_to_match&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Wed, 18 Jul 2007 16:18:13 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/need-help-with-a-script/m-p/4036748#M93964</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-07-18T16:18:13Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with a script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/need-help-with-a-script/m-p/4036749#M93965</link>
      <description>Example 1:&lt;BR /&gt;find / -type f -exec grep -l &lt;WORD&gt; {} \; &amp;gt; /tmp/logfile&lt;BR /&gt;&lt;BR /&gt;Example 2:&lt;BR /&gt;find / -type f -name *.txt -exec grep -l &lt;WORD&gt; {} \; &amp;gt; /tmp/logfile&lt;/WORD&gt;&lt;/WORD&gt;</description>
      <pubDate>Wed, 18 Jul 2007 18:07:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/need-help-with-a-script/m-p/4036749#M93965</guid>
      <dc:creator>Ivan Ferreira</dc:creator>
      <dc:date>2007-07-18T18:07:05Z</dc:date>
    </item>
  </channel>
</rss>

