<?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: Script help - grep for string with embedded spaces in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help-grep-for-string-with-embedded-spaces/m-p/3141100#M155296</link>
    <description>works if&lt;BR /&gt;&lt;BR /&gt;blank="\ "&lt;BR /&gt;match_string="$(date "+%b")$blank$(date "+%e")$blank$(date "+%H")"&lt;BR /&gt;&lt;BR /&gt;grep "$match_string" /var/adm/syslog/auth.log</description>
    <pubDate>Wed, 10 Dec 2003 11:06:56 GMT</pubDate>
    <dc:creator>Neil Dixon</dc:creator>
    <dc:date>2003-12-10T11:06:56Z</dc:date>
    <item>
      <title>Script help - grep for string with embedded spaces</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help-grep-for-string-with-embedded-spaces/m-p/3141095#M155291</link>
      <description>I need to grep auth.log for entries for the current date and hour.  So I set a match string as such:&lt;BR /&gt;&lt;BR /&gt;blank=" "&lt;BR /&gt;match_string="$(date "+%b") $blank  $(date "+%e") $(date "+%H")"&lt;BR /&gt;&lt;BR /&gt;(I am not sure yet if $blank is working; when I concatenate the three portions of the date fields I need a space between the month and day of the month).&lt;BR /&gt;&lt;BR /&gt;Currently $match_string = "Dec 10 09", so this looks good so far.&lt;BR /&gt;&lt;BR /&gt;I now want to grep auth.log for lines that match this string.  But I cannot seem to get a command that looks at the entire match string as one field.  I have tried:&lt;BR /&gt;&lt;BR /&gt;#grep $match_string /var/adm/syslog/auth.log&lt;BR /&gt;grep: can't open 10&lt;BR /&gt;grep: can't open 09&lt;BR /&gt;This is followed by listing all "Dec" entries.&lt;BR /&gt;&lt;BR /&gt;I have also tried:&lt;BR /&gt;grep "$match_string" /var/adm/syslog/auth.log&lt;BR /&gt;gives me no results at all.  &lt;BR /&gt;&lt;BR /&gt;What should be captured by the grep would (for example) be:&lt;BR /&gt;Dec 10 09:55:03 sshd[10843]: Accepted password...&lt;BR /&gt;Dec 10 09:55:03 su: + ...&lt;BR /&gt;&lt;BR /&gt;Any help would be appreciated.&lt;BR /&gt;&lt;BR /&gt;Scott Lindstrom</description>
      <pubDate>Wed, 10 Dec 2003 10:52:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help-grep-for-string-with-embedded-spaces/m-p/3141095#M155291</guid>
      <dc:creator>Scott Lindstrom_2</dc:creator>
      <dc:date>2003-12-10T10:52:23Z</dc:date>
    </item>
    <item>
      <title>Re: Script help - grep for string with embedded spaces</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help-grep-for-string-with-embedded-spaces/m-p/3141096#M155292</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;use grep "$match_string" /var/adm/syslog/auth.log&lt;BR /&gt;otherwise your line is evaluates to:&lt;BR /&gt;grep Dec 10 09 /var/adm/syslog/auth.log&lt;BR /&gt;which is obviously wrong syntax.&lt;BR /&gt;greetings, &lt;BR /&gt;&lt;BR /&gt;Michael&lt;BR /&gt;</description>
      <pubDate>Wed, 10 Dec 2003 10:58:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help-grep-for-string-with-embedded-spaces/m-p/3141096#M155292</guid>
      <dc:creator>Michael Schulte zur Sur</dc:creator>
      <dc:date>2003-12-10T10:58:50Z</dc:date>
    </item>
    <item>
      <title>Re: Script help - grep for string with embedded spaces</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help-grep-for-string-with-embedded-spaces/m-p/3141097#M155293</link>
      <description>You have too many spaces in your string.&lt;BR /&gt;&lt;BR /&gt;Try this:&lt;BR /&gt;&lt;BR /&gt;match_string=$(date +"%b %e %H")&lt;BR /&gt;grep "$match_string" /var/adm/syslog/auth.log&lt;BR /&gt;&lt;BR /&gt;-- Graham</description>
      <pubDate>Wed, 10 Dec 2003 11:02:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help-grep-for-string-with-embedded-spaces/m-p/3141097#M155293</guid>
      <dc:creator>Graham Cameron_1</dc:creator>
      <dc:date>2003-12-10T11:02:39Z</dc:date>
    </item>
    <item>
      <title>Re: Script help - grep for string with embedded spaces</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help-grep-for-string-with-embedded-spaces/m-p/3141098#M155294</link>
      <description>Michael -&lt;BR /&gt;&lt;BR /&gt;I had tried that and got no results.&lt;BR /&gt;&lt;BR /&gt;But now that I look back, I had no entries for the hour in the match string!  &lt;BR /&gt;&lt;BR /&gt;I was so caught up in looking for a valid syntax, that I forgot to look for the obvious reason.&lt;BR /&gt;&lt;BR /&gt;Scott</description>
      <pubDate>Wed, 10 Dec 2003 11:03:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help-grep-for-string-with-embedded-spaces/m-p/3141098#M155294</guid>
      <dc:creator>Scott Lindstrom_2</dc:creator>
      <dc:date>2003-12-10T11:03:06Z</dc:date>
    </item>
    <item>
      <title>Re: Script help - grep for string with embedded spaces</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help-grep-for-string-with-embedded-spaces/m-p/3141099#M155295</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;one should read all the email and not answer to quickly. ;-)&lt;BR /&gt;Try grep -i. Sometimes I get results with that. It should work, like you tried.&lt;BR /&gt;Is auth.log an ascii file?&lt;BR /&gt;&lt;BR /&gt;greetings,&lt;BR /&gt;&lt;BR /&gt;Michael&lt;BR /&gt;</description>
      <pubDate>Wed, 10 Dec 2003 11:04:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help-grep-for-string-with-embedded-spaces/m-p/3141099#M155295</guid>
      <dc:creator>Michael Schulte zur Sur</dc:creator>
      <dc:date>2003-12-10T11:04:47Z</dc:date>
    </item>
    <item>
      <title>Re: Script help - grep for string with embedded spaces</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help-grep-for-string-with-embedded-spaces/m-p/3141100#M155296</link>
      <description>works if&lt;BR /&gt;&lt;BR /&gt;blank="\ "&lt;BR /&gt;match_string="$(date "+%b")$blank$(date "+%e")$blank$(date "+%H")"&lt;BR /&gt;&lt;BR /&gt;grep "$match_string" /var/adm/syslog/auth.log</description>
      <pubDate>Wed, 10 Dec 2003 11:06:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help-grep-for-string-with-embedded-spaces/m-p/3141100#M155296</guid>
      <dc:creator>Neil Dixon</dc:creator>
      <dc:date>2003-12-10T11:06:56Z</dc:date>
    </item>
    <item>
      <title>Re: Script help - grep for string with embedded spaces</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help-grep-for-string-with-embedded-spaces/m-p/3141101#M155297</link>
      <description>First you don't need ${blank} as the shell will concatenate the $(date)'s and spaces within the quoted string just fine. I would change the "+%X"'s to single quotes because we want them to remain absolutely intact.&lt;BR /&gt;&lt;BR /&gt;match_string="$(date "+%b") $blank $(date "+%e") $(date "+%H")"&lt;BR /&gt;&lt;BR /&gt;should be:&lt;BR /&gt;match_string="$(date '+%b') $(date '+%e') $(date '+%H')"&lt;BR /&gt;then&lt;BR /&gt;grep "${match_string}" filename should work just fine.&lt;BR /&gt;&lt;BR /&gt;I would do this first so that you can see exactly what ${match_string is set to -- it's difficult to know if you have spaces or tabs just wiewing your posting because of the way HTML handles whitespace.&lt;BR /&gt;&lt;BR /&gt;echo "Match_string = \"${match_string}\""&lt;BR /&gt;&lt;BR /&gt;When you get the spaces to exactly match what is in your file then grep should work like a charm iff you double quote the expression to match so that the variable is expanded AND passed as one argument to grep.&lt;BR /&gt;</description>
      <pubDate>Wed, 10 Dec 2003 11:08:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help-grep-for-string-with-embedded-spaces/m-p/3141101#M155297</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2003-12-10T11:08:04Z</dc:date>
    </item>
    <item>
      <title>Re: Script help - grep for string with embedded spaces</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help-grep-for-string-with-embedded-spaces/m-p/3141102#M155298</link>
      <description>Graham -&lt;BR /&gt;&lt;BR /&gt;match_string=$(date +"%b %e %H") works great (given that today is day 10).  &lt;BR /&gt;&lt;BR /&gt;Clay -&lt;BR /&gt;&lt;BR /&gt;The reason that the space seemed to be an issue is yesterday's auth.log entries look like:&lt;BR /&gt;Dec  9 15:15:04&lt;BR /&gt;&lt;BR /&gt;Today's auth.log entries look like:&lt;BR /&gt;Dec 10 07:07:04&lt;BR /&gt;&lt;BR /&gt;Even though I understand %e is supposed to return the day of the month with a leading space, when I tried it with the three fields concatenated, I was getting "Dec 9 15" instead of "Dec  9 15".  I may have to find a system in which I can set the date back to try this some more today.&lt;BR /&gt;&lt;BR /&gt;Scott&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 10 Dec 2003 11:17:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help-grep-for-string-with-embedded-spaces/m-p/3141102#M155298</guid>
      <dc:creator>Scott Lindstrom_2</dc:creator>
      <dc:date>2003-12-10T11:17:40Z</dc:date>
    </item>
    <item>
      <title>Re: Script help - grep for string with embedded spaces</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help-grep-for-string-with-embedded-spaces/m-p/3141103#M155299</link>
      <description>The posting I just did does not show that:&lt;BR /&gt;&lt;BR /&gt;Dec 9 15:15:04&lt;BR /&gt;&lt;BR /&gt;should have two spaces between Dec and 9.&lt;BR /&gt;&lt;BR /&gt;Scott</description>
      <pubDate>Wed, 10 Dec 2003 11:31:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help-grep-for-string-with-embedded-spaces/m-p/3141103#M155299</guid>
      <dc:creator>Scott Lindstrom_2</dc:creator>
      <dc:date>2003-12-10T11:31:02Z</dc:date>
    </item>
    <item>
      <title>Re: Script help - grep for string with embedded spaces</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help-grep-for-string-with-embedded-spaces/m-p/3141104#M155300</link>
      <description>Neil -&lt;BR /&gt;&lt;BR /&gt;I tried:&lt;BR /&gt;blank="\ "&lt;BR /&gt;print $blank&lt;BR /&gt;&lt;BR /&gt;and get back \ as the value of $blank.&lt;BR /&gt;&lt;BR /&gt;Am I missing something here?&lt;BR /&gt;&lt;BR /&gt;Scott</description>
      <pubDate>Wed, 10 Dec 2003 12:00:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help-grep-for-string-with-embedded-spaces/m-p/3141104#M155300</guid>
      <dc:creator>Scott Lindstrom_2</dc:creator>
      <dc:date>2003-12-10T12:00:52Z</dc:date>
    </item>
    <item>
      <title>Re: Script help - grep for string with embedded spaces</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help-grep-for-string-with-embedded-spaces/m-p/3141105#M155301</link>
      <description>Hi Scott,&lt;BR /&gt;&lt;BR /&gt;are you still having trouble?&lt;BR /&gt;&lt;BR /&gt;greetings,&lt;BR /&gt;&lt;BR /&gt;Michael&lt;BR /&gt;</description>
      <pubDate>Wed, 10 Dec 2003 12:04:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help-grep-for-string-with-embedded-spaces/m-p/3141105#M155301</guid>
      <dc:creator>Michael Schulte zur Sur</dc:creator>
      <dc:date>2003-12-10T12:04:45Z</dc:date>
    </item>
    <item>
      <title>Re: Script help - grep for string with embedded spaces</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help-grep-for-string-with-embedded-spaces/m-p/3141106#M155302</link>
      <description>Okay, if date '%e' is behaving a little strangely then we need to use typeset to assign each component. I would first look for any patches for date and apply them. I don't like it when commands don't behave as advertised but I have seen it. This workaround will fix you:&lt;BR /&gt;&lt;BR /&gt;e.g.&lt;BR /&gt;typeset -R2 MDAY=$(date '+%e')&lt;BR /&gt;match_string="$(date '+%b') ${MDAY} $(date '+%H')" &lt;BR /&gt;&lt;BR /&gt;and will right justify to 2 positions and fill with leading spaces regardless if the day is a one or two digit value.&lt;BR /&gt;</description>
      <pubDate>Wed, 10 Dec 2003 12:06:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help-grep-for-string-with-embedded-spaces/m-p/3141106#M155302</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2003-12-10T12:06:54Z</dc:date>
    </item>
    <item>
      <title>Re: Script help - grep for string with embedded spaces</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help-grep-for-string-with-embedded-spaces/m-p/3141107#M155303</link>
      <description>Michael -&lt;BR /&gt;&lt;BR /&gt;Still working my way thru testing the various replies.  Things are looking very good.  (I think I may be all set, but not 100% sure).&lt;BR /&gt;&lt;BR /&gt;These forums are great!  Getting so many valuable replies that I am behind in trying them is a great situation to be in!&lt;BR /&gt;&lt;BR /&gt;Scott</description>
      <pubDate>Wed, 10 Dec 2003 12:18:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help-grep-for-string-with-embedded-spaces/m-p/3141107#M155303</guid>
      <dc:creator>Scott Lindstrom_2</dc:creator>
      <dc:date>2003-12-10T12:18:21Z</dc:date>
    </item>
  </channel>
</rss>

