<?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: Search all text files for a string in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/search-all-text-files-for-a-string/m-p/2631764#M849972</link>
    <description>I recently had to do this for an Oracle upgrade - searching for all scripts etc that referred to the old ORACLE_HOME.&lt;BR /&gt;&lt;BR /&gt;In the end I simply resorted to using "grep -l" to print the file name rather than the matching lines.  ie:&lt;BR /&gt;&lt;BR /&gt;# find / -type f | xargs grep -l "string" &amp;gt; /tmp/log 2&amp;gt;&amp;amp;1&lt;BR /&gt;&lt;BR /&gt;That way you just get a list of files that contain the match and you can decide which ones are binary and which ones arent.  &lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Steve</description>
    <pubDate>Tue, 18 Dec 2001 16:50:06 GMT</pubDate>
    <dc:creator>Steven Gillard_2</dc:creator>
    <dc:date>2001-12-18T16:50:06Z</dc:date>
    <item>
      <title>Search all text files for a string</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/search-all-text-files-for-a-string/m-p/2631757#M849965</link>
      <description>Hi all,&lt;BR /&gt;&lt;BR /&gt;I'm trying to search all text files on the system for a specific string.  My results haven't been very good so far.  I'm having a problem selecting only text files, I'm missing some files I shouldn't, and some lines are too long for vi (when I try to edit the results file).&lt;BR /&gt;&lt;BR /&gt;Anyone got something to help?&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Darrell</description>
      <pubDate>Mon, 17 Dec 2001 20:17:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/search-all-text-files-for-a-string/m-p/2631757#M849965</guid>
      <dc:creator>Darrell Allen</dc:creator>
      <dc:date>2001-12-17T20:17:50Z</dc:date>
    </item>
    <item>
      <title>Re: Search all text files for a string</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/search-all-text-files-for-a-string/m-p/2631758#M849966</link>
      <description>try this&lt;BR /&gt;&lt;BR /&gt;find / -type f | xargs grep string</description>
      <pubDate>Mon, 17 Dec 2001 20:21:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/search-all-text-files-for-a-string/m-p/2631758#M849966</guid>
      <dc:creator>Jeff Machols</dc:creator>
      <dc:date>2001-12-17T20:21:17Z</dc:date>
    </item>
    <item>
      <title>Re: Search all text files for a string</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/search-all-text-files-for-a-string/m-p/2631759#M849967</link>
      <description>Hi Darrell:&lt;BR /&gt;&lt;BR /&gt;You might try something close to this:&lt;BR /&gt;&lt;BR /&gt;find . -type f | while read X&lt;BR /&gt;do&lt;BR /&gt;   file ${X} | grep -q -i "ascii text"&lt;BR /&gt;   STAT=$?&lt;BR /&gt;   if [ ${STAT} -eq 0 ]&lt;BR /&gt;      then&lt;BR /&gt;        grep -q -i "Your target string" ${X}&lt;BR /&gt;        STAT=$?&lt;BR /&gt;        if [ ${STAT} -eq 0 ]&lt;BR /&gt;          then&lt;BR /&gt;            echo "File: ${X}"&lt;BR /&gt;            grep -i "Your target string" ${X}&lt;BR /&gt;          fi&lt;BR /&gt;      fi&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;You could, of course also pass in "Your target string" as $1&lt;BR /&gt;</description>
      <pubDate>Mon, 17 Dec 2001 20:41:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/search-all-text-files-for-a-string/m-p/2631759#M849967</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2001-12-17T20:41:52Z</dc:date>
    </item>
    <item>
      <title>Re: Search all text files for a string</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/search-all-text-files-for-a-string/m-p/2631760#M849968</link>
      <description>Hello Darrell,&lt;BR /&gt;&lt;BR /&gt;this is not so simple, really!&lt;BR /&gt;Usually something like this is working, but "file" tests only for the first 128 bytes of a file...&lt;BR /&gt;&lt;BR /&gt;find / -type f -print |&lt;BR /&gt;while read name; do case $(file $name) in &lt;BR /&gt;*text*) grep -i "PATTERN" $name /dev/null ;;&lt;BR /&gt;esac;done&lt;BR /&gt;&lt;BR /&gt;First, you get only the files (no devices, pipes, directories, links), then you select the *text files* (ascii, C, awk, english...), and then you use "grep" on those. The additional parameter "/dev/null" forces "grep" to show the name of file and the line containing the match...&lt;BR /&gt;&lt;BR /&gt;HTH,&lt;BR /&gt;Wodisc</description>
      <pubDate>Mon, 17 Dec 2001 20:43:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/search-all-text-files-for-a-string/m-p/2631760#M849968</guid>
      <dc:creator>Wodisch</dc:creator>
      <dc:date>2001-12-17T20:43:44Z</dc:date>
    </item>
    <item>
      <title>Re: Search all text files for a string</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/search-all-text-files-for-a-string/m-p/2631761#M849969</link>
      <description>Hi Darell,&lt;BR /&gt; &lt;BR /&gt;find $DIR | xargs file |grep "ascii text" | awk '{ print $1}' | sed 's/://g' &amp;gt;file_list&lt;BR /&gt;&lt;BR /&gt;for i in `cat file_list``&lt;BR /&gt;do&lt;BR /&gt;  grep ""yourstuff""  $i&lt;BR /&gt;  if [ $? -eq 0 ]&lt;BR /&gt;  then&lt;BR /&gt;    echo "$i" &amp;gt;&amp;gt;Caught&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;HTH&lt;BR /&gt;raj</description>
      <pubDate>Mon, 17 Dec 2001 22:27:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/search-all-text-files-for-a-string/m-p/2631761#M849969</guid>
      <dc:creator>Roger Baptiste</dc:creator>
      <dc:date>2001-12-17T22:27:45Z</dc:date>
    </item>
    <item>
      <title>Re: Search all text files for a string</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/search-all-text-files-for-a-string/m-p/2631762#M849970</link>
      <description>find ./ -name "*" -exec grep -il 'Pattern_to_match' {} \;|xargs file|grep asci&amp;gt;log might work</description>
      <pubDate>Tue, 18 Dec 2001 16:13:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/search-all-text-files-for-a-string/m-p/2631762#M849970</guid>
      <dc:creator>Thom Cornwell</dc:creator>
      <dc:date>2001-12-18T16:13:02Z</dc:date>
    </item>
    <item>
      <title>Re: Search all text files for a string</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/search-all-text-files-for-a-string/m-p/2631763#M849971</link>
      <description>Hi&lt;BR /&gt;&lt;BR /&gt;find . -type f -print -exec grep &lt;STRING&gt; {} \;&lt;BR /&gt;&lt;BR /&gt;search for a string inside files.&lt;BR /&gt;&lt;BR /&gt;HTH&lt;BR /&gt;&lt;BR /&gt;Paula&lt;/STRING&gt;</description>
      <pubDate>Tue, 18 Dec 2001 16:16:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/search-all-text-files-for-a-string/m-p/2631763#M849971</guid>
      <dc:creator>Paula J Frazer-Campbell</dc:creator>
      <dc:date>2001-12-18T16:16:17Z</dc:date>
    </item>
    <item>
      <title>Re: Search all text files for a string</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/search-all-text-files-for-a-string/m-p/2631764#M849972</link>
      <description>I recently had to do this for an Oracle upgrade - searching for all scripts etc that referred to the old ORACLE_HOME.&lt;BR /&gt;&lt;BR /&gt;In the end I simply resorted to using "grep -l" to print the file name rather than the matching lines.  ie:&lt;BR /&gt;&lt;BR /&gt;# find / -type f | xargs grep -l "string" &amp;gt; /tmp/log 2&amp;gt;&amp;amp;1&lt;BR /&gt;&lt;BR /&gt;That way you just get a list of files that contain the match and you can decide which ones are binary and which ones arent.  &lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Steve</description>
      <pubDate>Tue, 18 Dec 2001 16:50:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/search-all-text-files-for-a-string/m-p/2631764#M849972</guid>
      <dc:creator>Steven Gillard_2</dc:creator>
      <dc:date>2001-12-18T16:50:06Z</dc:date>
    </item>
    <item>
      <title>Re: Search all text files for a string</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/search-all-text-files-for-a-string/m-p/2631765#M849973</link>
      <description>Hi all,&lt;BR /&gt;&lt;BR /&gt;Thanks for the replies.  They are appreciated!  Just wanted you to know I'm still testing these suggestions and haven't forgotten to assign points.&lt;BR /&gt;&lt;BR /&gt;Darrell</description>
      <pubDate>Tue, 18 Dec 2001 21:59:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/search-all-text-files-for-a-string/m-p/2631765#M849973</guid>
      <dc:creator>Darrell Allen</dc:creator>
      <dc:date>2001-12-18T21:59:31Z</dc:date>
    </item>
    <item>
      <title>Re: Search all text files for a string</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/search-all-text-files-for-a-string/m-p/2631766#M849974</link>
      <description>Hi Darrell,&lt;BR /&gt;&lt;BR /&gt;Consider the script lookForString.sh with two arguments : arg1 is the directory under which you are looking for string and arg2 is the string you are looking for.&lt;BR /&gt;&lt;BR /&gt;find $1 -type f | while read File&lt;BR /&gt;do &lt;BR /&gt;  file ${File} | grep -q -i "ascii text" &lt;BR /&gt;  rFile=$? &lt;BR /&gt;  if [ ${rFile} -eq 0 ] &lt;BR /&gt;  then &lt;BR /&gt;      grep -q -i "Your target string" ${File} &lt;BR /&gt;      rString=$? &lt;BR /&gt;      if [ ${rString} -eq 0 ] &lt;BR /&gt;      then &lt;BR /&gt;          echo "### File '${File}' contains string '$2'"  &lt;BR /&gt;      fi &lt;BR /&gt;  fi &lt;BR /&gt;done &lt;BR /&gt;&lt;BR /&gt;Magdi&lt;BR /&gt;</description>
      <pubDate>Wed, 19 Dec 2001 09:06:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/search-all-text-files-for-a-string/m-p/2631766#M849974</guid>
      <dc:creator>Magdi KAMAL</dc:creator>
      <dc:date>2001-12-19T09:06:15Z</dc:date>
    </item>
    <item>
      <title>Re: Search all text files for a string</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/search-all-text-files-for-a-string/m-p/2631767#M849975</link>
      <description>Hi again,&lt;BR /&gt;&lt;BR /&gt;Thanks for everyone's help.  Wodisch sums up my testing rather well:  "this is not so simple, really!"&lt;BR /&gt;&lt;BR /&gt;My problem was also due to a database upgrade (Progress 83b to 83d).  Why do people hard-code something like a version number in scripts?  Haven't they ever heard of symlinks?  I just finished going thru the resulting list of 415 files that contained 83b and changing them so that they don't reference a version number any more!  Thankfully I won't have this problem again!&lt;BR /&gt;&lt;BR /&gt;I tried each of the suggestions above (with some minor, I think, changes).  See the attachment for what I ran, timex output, and problems noted with each.  Note that each of the 4 scripts in the attachment found the same number of files if I limited my find to /etc.  When finding from "/" is where the miscellaneous problems arose.&lt;BR /&gt;&lt;BR /&gt;Steven's suggestion to use "grep -l" to list the filenames without the line that matched was a big help.  Filenames were what I really wanted anyway and solves the problem with some lines of my output being too long for vi, awk, etc.&lt;BR /&gt;&lt;BR /&gt;I think another problem is using xargs with the large number of files returned by find.  Perhaps this can be avoided by coding a loop on all mounted filesystems and using the -xdev arg of find.  I didn't try that.  In any event, that problem didn't seem to happen in the following (which is what worked best for me):&lt;BR /&gt;&lt;BR /&gt;find / -type f -exec grep -l 83b {} \; | xargs file | grep text | awk -F: '{print $1}'&lt;BR /&gt;&lt;BR /&gt;Thanks again,&lt;BR /&gt;Darrell</description>
      <pubDate>Wed, 19 Dec 2001 18:33:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/search-all-text-files-for-a-string/m-p/2631767#M849975</guid>
      <dc:creator>Darrell Allen</dc:creator>
      <dc:date>2001-12-19T18:33:27Z</dc:date>
    </item>
  </channel>
</rss>

