<?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: Shell script: Checking if a particular string exists in a file in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-checking-if-a-particular-string-exists-in-a-file/m-p/3004188#M127101</link>
    <description>why don't you try:&lt;BR /&gt;&lt;BR /&gt;#!/bin/sh &lt;BR /&gt;if grep "pglcls01" syslog.conf &amp;gt;&amp;gt; /dev/null; then &lt;BR /&gt;echo Here &lt;BR /&gt;else &lt;BR /&gt;echo "echo \"my string here\"" &amp;gt;&amp;gt; /home/file1 &lt;BR /&gt;fi &lt;BR /&gt;&lt;BR /&gt;or another way...&lt;BR /&gt;&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;y=`grep "pglcls01" syslog.conf|wc -l`&lt;BR /&gt;&lt;BR /&gt;if [ $y -gt 1 ]; then&lt;BR /&gt;echo Here&lt;BR /&gt;else&lt;BR /&gt;echo "echo \"my string here\"" &amp;gt;&amp;gt; /home/file1 &lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;Also, how what is the syntax to to check if a value is greater than or equal (&amp;gt;=) in SHELL script? &lt;BR /&gt;ans: -ge&lt;BR /&gt;</description>
    <pubDate>Mon, 23 Jun 2003 15:57:23 GMT</pubDate>
    <dc:creator>Edgar Avila</dc:creator>
    <dc:date>2003-06-23T15:57:23Z</dc:date>
    <item>
      <title>Shell script: Checking if a particular string exists in a file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-checking-if-a-particular-string-exists-in-a-file/m-p/3004177#M127090</link>
      <description>HI,&lt;BR /&gt;I would like to check if a particular string exists in a file, and if it doesn't, then insert that string in the file.&lt;BR /&gt;&lt;BR /&gt;I was wondering if anyone could show me how I could perform such checks in a SHELL script?&lt;BR /&gt;&lt;BR /&gt;I tried the following method below but it did not work:&lt;BR /&gt;&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;if [grep "pglcls01" syslog.conf|wc -l gt 1];then&lt;BR /&gt;   echo Here&lt;BR /&gt;else&lt;BR /&gt;   echo "echo "my string   here" &amp;gt;&amp;gt; /home/file1&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;duran% ./sys-1&lt;BR /&gt;./sys-1: [grep: command not found&lt;BR /&gt;wc: gt: No such file or directory&lt;BR /&gt;wc: 1]: No such file or directory&lt;BR /&gt;      0 total&lt;BR /&gt;duran% ls -l syslog*&lt;BR /&gt;-rw-r-----    1 premir    eng           390 Jun 17 17:38 syslog.conf&lt;BR /&gt;&lt;BR /&gt;Also, how what is the syntax to to check if a value is greater than or equal (&amp;gt;=) in SHELL script?&lt;BR /&gt;&lt;BR /&gt;Could some kindly help me out?&lt;BR /&gt;&lt;BR /&gt;Thanks in advance.&lt;BR /&gt;</description>
      <pubDate>Sun, 22 Jun 2003 07:50:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-checking-if-a-particular-string-exists-in-a-file/m-p/3004177#M127090</guid>
      <dc:creator>Peter Remirez</dc:creator>
      <dc:date>2003-06-22T07:50:47Z</dc:date>
    </item>
    <item>
      <title>Re: Shell script: Checking if a particular string exists in a file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-checking-if-a-particular-string-exists-in-a-file/m-p/3004178#M127091</link>
      <description>Hi Peter,&lt;BR /&gt;&lt;BR /&gt;There are syntax errors in your script. I modified it to work.&lt;BR /&gt;&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;if [ $(grep "pglcls01" syslog.conf|wc -l) -gt 1 ]&lt;BR /&gt;then&lt;BR /&gt;echo Here&lt;BR /&gt;else&lt;BR /&gt;echo "echo "my string here"" &amp;gt;&amp;gt; /home/file1&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;$(commmand) will evaluate the command. You could also use the back ticks (`grep pglcls01 syslog.conf`).&lt;BR /&gt;&lt;BR /&gt;-Sri</description>
      <pubDate>Sun, 22 Jun 2003 08:19:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-checking-if-a-particular-string-exists-in-a-file/m-p/3004178#M127091</guid>
      <dc:creator>Sridhar Bhaskarla</dc:creator>
      <dc:date>2003-06-22T08:19:51Z</dc:date>
    </item>
    <item>
      <title>Re: Shell script: Checking if a particular string exists in a file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-checking-if-a-particular-string-exists-in-a-file/m-p/3004179#M127092</link>
      <description>Hi,&lt;BR /&gt;If you just want to check if a string exist in a file you can use the return code:&lt;BR /&gt;&lt;BR /&gt;If grep &lt;STRING&gt; &lt;FILE&gt; &amp;gt;/dev/null 2&amp;gt;&amp;amp;1&lt;BR /&gt;then&lt;BR /&gt;echo "String exist"&lt;BR /&gt;else&lt;BR /&gt;echo "String don't exist"&lt;BR /&gt;fi&lt;/FILE&gt;&lt;/STRING&gt;</description>
      <pubDate>Sun, 22 Jun 2003 13:31:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-checking-if-a-particular-string-exists-in-a-file/m-p/3004179#M127092</guid>
      <dc:creator>Leif Halvarsson_2</dc:creator>
      <dc:date>2003-06-22T13:31:33Z</dc:date>
    </item>
    <item>
      <title>Re: Shell script: Checking if a particular string exists in a file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-checking-if-a-particular-string-exists-in-a-file/m-p/3004180#M127093</link>
      <description>Is there a spesific area where you want to add the string.&lt;BR /&gt;&lt;BR /&gt;At the end of the file?&lt;BR /&gt;In the beginning of the file?&lt;BR /&gt;Somewhere in the middle?&lt;BR /&gt;In the beginning of the line or at the end of the line?&lt;BR /&gt;&lt;BR /&gt;finding if a string of text exists is easy. placing new text in a flat file is also very straitforward, just let me know the answers to these questions and I'll write you a routine - do you prefer perl or shell scripts?</description>
      <pubDate>Sun, 22 Jun 2003 15:38:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-checking-if-a-particular-string-exists-in-a-file/m-p/3004180#M127093</guid>
      <dc:creator>Donny Jekels</dc:creator>
      <dc:date>2003-06-22T15:38:35Z</dc:date>
    </item>
    <item>
      <title>Re: Shell script: Checking if a particular string exists in a file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-checking-if-a-particular-string-exists-in-a-file/m-p/3004181#M127094</link>
      <description>Hello!&lt;BR /&gt;&lt;BR /&gt;Try the next in csh:&lt;BR /&gt;&lt;BR /&gt;grep -q "String" &lt;FILENAME&gt; &amp;gt;&amp;amp; /dev/null&lt;BR /&gt;&lt;BR /&gt;if ($status == 0) then &lt;BR /&gt;   echo "String exist" &lt;BR /&gt;else &lt;BR /&gt;   echo "String" &amp;gt;&amp;gt; &lt;FILENAME&gt; &lt;BR /&gt;endif&lt;BR /&gt;&lt;BR /&gt;Caesar&lt;/FILENAME&gt;&lt;/FILENAME&gt;</description>
      <pubDate>Sun, 22 Jun 2003 18:12:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-checking-if-a-particular-string-exists-in-a-file/m-p/3004181#M127094</guid>
      <dc:creator>Caesar_3</dc:creator>
      <dc:date>2003-06-22T18:12:26Z</dc:date>
    </item>
    <item>
      <title>Re: Shell script: Checking if a particular string exists in a file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-checking-if-a-particular-string-exists-in-a-file/m-p/3004182#M127095</link>
      <description>Hi,just a simple way to check if a string exists in a file:&lt;BR /&gt;&lt;BR /&gt;if grep "String" file &amp;gt;/dev/null 2&amp;gt;&amp;amp;1&lt;BR /&gt;then&lt;BR /&gt;echo "String exists!"&lt;BR /&gt;else&lt;BR /&gt;echo "String" &amp;gt;&amp;gt;file&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;To check if a value is greater than or equal, you can use:&lt;BR /&gt;if [ ! $a -lt 10 ]&lt;BR /&gt;&lt;BR /&gt;Good luck!&lt;BR /&gt;-ux</description>
      <pubDate>Sun, 22 Jun 2003 23:44:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-checking-if-a-particular-string-exists-in-a-file/m-p/3004182#M127095</guid>
      <dc:creator>Fragon</dc:creator>
      <dc:date>2003-06-22T23:44:51Z</dc:date>
    </item>
    <item>
      <title>Re: Shell script: Checking if a particular string exists in a file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-checking-if-a-particular-string-exists-in-a-file/m-p/3004183#M127096</link>
      <description>Donny,&lt;BR /&gt;I would like to have the string preferably at the beginning of the file. &lt;BR /&gt;&lt;BR /&gt;If possible, would like to have the script to written in SHELL.&lt;BR /&gt;&lt;BR /&gt;Thanks very much.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 23 Jun 2003 02:52:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-checking-if-a-particular-string-exists-in-a-file/m-p/3004183#M127096</guid>
      <dc:creator>Peter Remirez</dc:creator>
      <dc:date>2003-06-23T02:52:06Z</dc:date>
    </item>
    <item>
      <title>Re: Shell script: Checking if a particular string exists in a file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-checking-if-a-particular-string-exists-in-a-file/m-p/3004184#M127097</link>
      <description>Just for text file:&lt;BR /&gt;&lt;BR /&gt;if ...&lt;BR /&gt;then&lt;BR /&gt;...&lt;BR /&gt;else&lt;BR /&gt;echo "String" &amp;gt;$$.tmp&lt;BR /&gt;cat file &amp;gt;&amp;gt;$$.tmp&lt;BR /&gt;cat $$.tmp &amp;gt;file&lt;BR /&gt;rm $$.tmp&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;Good luck!&lt;BR /&gt;-ux</description>
      <pubDate>Mon, 23 Jun 2003 05:18:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-checking-if-a-particular-string-exists-in-a-file/m-p/3004184#M127097</guid>
      <dc:creator>Fragon</dc:creator>
      <dc:date>2003-06-23T05:18:43Z</dc:date>
    </item>
    <item>
      <title>Re: Shell script: Checking if a particular string exists in a file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-checking-if-a-particular-string-exists-in-a-file/m-p/3004185#M127098</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;So it could b :&lt;BR /&gt;&lt;BR /&gt;if grep -q "pglcls01" syslog.conf&lt;BR /&gt;then&lt;BR /&gt;  echo Here&lt;BR /&gt;else&lt;BR /&gt;  (&lt;BR /&gt;    echo "Mystring"&lt;BR /&gt;    cat /home/file1&lt;BR /&gt;  ) &amp;gt; /tmp/tmp$$&lt;BR /&gt;  mv /home/file1 /home/file1.prev&lt;BR /&gt;  mv /tmp/tmp$$ /home/file1&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;Regards.</description>
      <pubDate>Mon, 23 Jun 2003 05:20:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-checking-if-a-particular-string-exists-in-a-file/m-p/3004185#M127098</guid>
      <dc:creator>Jean-Louis Phelix</dc:creator>
      <dc:date>2003-06-23T05:20:43Z</dc:date>
    </item>
    <item>
      <title>Re: Shell script: Checking if a particular string exists in a file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-checking-if-a-particular-string-exists-in-a-file/m-p/3004186#M127099</link>
      <description>#!/bin/sh&lt;BR /&gt;CHK=`cat /etc/syslog.conf | grep pglcls01| wc -l`&lt;BR /&gt;if [ $CHK != 0 ]&lt;BR /&gt;then&lt;BR /&gt;echo "required string  exists"&lt;BR /&gt;else&lt;BR /&gt;echo pglcls01 &amp;gt;&amp;gt; /etc/syslog.conf&lt;BR /&gt;fi</description>
      <pubDate>Mon, 23 Jun 2003 05:42:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-checking-if-a-particular-string-exists-in-a-file/m-p/3004186#M127099</guid>
      <dc:creator>Siddhartha M</dc:creator>
      <dc:date>2003-06-23T05:42:36Z</dc:date>
    </item>
    <item>
      <title>Re: Shell script: Checking if a particular string exists in a file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-checking-if-a-particular-string-exists-in-a-file/m-p/3004187#M127100</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;Compleating my previous example. The string is added to the beginning of the file if it not exists.&lt;BR /&gt;&lt;BR /&gt;If ! grep -q "string" &lt;FILE&gt; 2&amp;gt;/dev/null&lt;BR /&gt;then&lt;BR /&gt;echo "string" &amp;gt;tmpfile&lt;BR /&gt;cat &lt;FILE&gt; &amp;gt;&amp;gt;tmpfile &lt;BR /&gt;mv tmpfile &lt;FILE&gt;&lt;BR /&gt;fi&lt;/FILE&gt;&lt;/FILE&gt;&lt;/FILE&gt;</description>
      <pubDate>Mon, 23 Jun 2003 07:38:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-checking-if-a-particular-string-exists-in-a-file/m-p/3004187#M127100</guid>
      <dc:creator>Leif Halvarsson_2</dc:creator>
      <dc:date>2003-06-23T07:38:00Z</dc:date>
    </item>
    <item>
      <title>Re: Shell script: Checking if a particular string exists in a file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-checking-if-a-particular-string-exists-in-a-file/m-p/3004188#M127101</link>
      <description>why don't you try:&lt;BR /&gt;&lt;BR /&gt;#!/bin/sh &lt;BR /&gt;if grep "pglcls01" syslog.conf &amp;gt;&amp;gt; /dev/null; then &lt;BR /&gt;echo Here &lt;BR /&gt;else &lt;BR /&gt;echo "echo \"my string here\"" &amp;gt;&amp;gt; /home/file1 &lt;BR /&gt;fi &lt;BR /&gt;&lt;BR /&gt;or another way...&lt;BR /&gt;&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;y=`grep "pglcls01" syslog.conf|wc -l`&lt;BR /&gt;&lt;BR /&gt;if [ $y -gt 1 ]; then&lt;BR /&gt;echo Here&lt;BR /&gt;else&lt;BR /&gt;echo "echo \"my string here\"" &amp;gt;&amp;gt; /home/file1 &lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;Also, how what is the syntax to to check if a value is greater than or equal (&amp;gt;=) in SHELL script? &lt;BR /&gt;ans: -ge&lt;BR /&gt;</description>
      <pubDate>Mon, 23 Jun 2003 15:57:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-checking-if-a-particular-string-exists-in-a-file/m-p/3004188#M127101</guid>
      <dc:creator>Edgar Avila</dc:creator>
      <dc:date>2003-06-23T15:57:23Z</dc:date>
    </item>
    <item>
      <title>Re: Shell script: Checking if a particular string exists in a file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-checking-if-a-particular-string-exists-in-a-file/m-p/3004189#M127102</link>
      <description>Hello!&lt;BR /&gt;&lt;BR /&gt;Return to my option:&lt;BR /&gt;&lt;BR /&gt;grep -q "String" &lt;FILENAME&gt; &amp;gt;&amp;amp; /dev/null &lt;BR /&gt;&lt;BR /&gt;if ($status == 0) then &lt;BR /&gt;  echo "String" &amp;gt; /tmp/temp.$$&lt;BR /&gt;  cat LOGFILE &amp;gt;&amp;gt; /tmp/temp.$$&lt;BR /&gt;  mv -f /tmp/temp.$$ LOGFILE&lt;BR /&gt;endif &lt;BR /&gt;&lt;BR /&gt;Caesar&lt;/FILENAME&gt;</description>
      <pubDate>Wed, 25 Jun 2003 17:22:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-checking-if-a-particular-string-exists-in-a-file/m-p/3004189#M127102</guid>
      <dc:creator>Caesar_3</dc:creator>
      <dc:date>2003-06-25T17:22:59Z</dc:date>
    </item>
  </channel>
</rss>

