<?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: Awk question? in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-question/m-p/4508022#M681152</link>
    <description>Hi Allan:&lt;BR /&gt;&lt;BR /&gt;Perhaps:&lt;BR /&gt;&lt;BR /&gt;# perl -nle '/((?:\d+\.?)+).+rptid=(\d+)/ and print join ":",$1,$2' file&lt;BR /&gt;&lt;BR /&gt;1.1.1.1:011157032&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
    <pubDate>Mon, 05 Oct 2009 18:30:33 GMT</pubDate>
    <dc:creator>James R. Ferguson</dc:creator>
    <dc:date>2009-10-05T18:30:33Z</dc:date>
    <item>
      <title>Awk question?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-question/m-p/4508020#M681150</link>
      <description>&lt;BR /&gt;I have the following entry in my web logs - &lt;BR /&gt;&lt;BR /&gt;1.1.1.1   -       -       [17/Sep/2009:03:14:50 -0700]    "GET /c14/v23.129/011157032/getlocalstring?template=calendar HTTP/1.1"  200     8941    "https://URL/c14/v28.129/011157032/reports/execute?rptid=011157032-VEND_BAL_DET-view-1253182486693"   "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; GTB6; .NET CLR 2.0.50727; OfficeLiveConnector.1.3; OfficeLivePatch.0.0; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)"       URL       80      -       -       -       0       "-"     "1.1.1.1.232161235455457383"&lt;BR /&gt;&lt;BR /&gt;I need to get the IP address(1.1.1.1-this can vary) and account id(011157032- this can vary) from each of the entries which are of this pattern within the web logs.&lt;BR /&gt;&lt;BR /&gt;How do I get them?&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Allan&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 05 Oct 2009 17:48:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-question/m-p/4508020#M681150</guid>
      <dc:creator>Allanm</dc:creator>
      <dc:date>2009-10-05T17:48:14Z</dc:date>
    </item>
    <item>
      <title>Re: Awk question?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-question/m-p/4508021#M681151</link>
      <description>You may want to consider the PERL regex over AWK.&lt;BR /&gt;&lt;BR /&gt;Here is something that works with the example in a file 'test'.&lt;BR /&gt;&lt;BR /&gt;$ perl -ne 'print qq(ip=$1 acc=$2\n) if m%^(\S+)\s.*?/(\d+)/\w+%' test&lt;BR /&gt;ip=1.1.1.1 acc=011157032&lt;BR /&gt;&lt;BR /&gt;Now the string 1.1.1.1 appears twice. Which one is authorative?&lt;BR /&gt;&lt;BR /&gt;I picked the fist one as being all the non-space starting at the begin of the line.&lt;BR /&gt;&lt;BR /&gt;The Account number appears 3 times? Which one will always be there, which one has the most predictable 'surroundings'?&lt;BR /&gt;&lt;BR /&gt;I picked the first one between two slashes and being followed by a word (getlocalstring in the example) followed by a ?&lt;BR /&gt;&lt;BR /&gt;For a better solution, please provide a better problem description!&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Hein&lt;BR /&gt;</description>
      <pubDate>Mon, 05 Oct 2009 18:12:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-question/m-p/4508021#M681151</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2009-10-05T18:12:05Z</dc:date>
    </item>
    <item>
      <title>Re: Awk question?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-question/m-p/4508022#M681152</link>
      <description>Hi Allan:&lt;BR /&gt;&lt;BR /&gt;Perhaps:&lt;BR /&gt;&lt;BR /&gt;# perl -nle '/((?:\d+\.?)+).+rptid=(\d+)/ and print join ":",$1,$2' file&lt;BR /&gt;&lt;BR /&gt;1.1.1.1:011157032&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Mon, 05 Oct 2009 18:30:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-question/m-p/4508022#M681152</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-10-05T18:30:33Z</dc:date>
    </item>
    <item>
      <title>Re: Awk question?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-question/m-p/4508023#M681153</link>
      <description>&lt;!--!*#--&gt;While this is certainly possible with awk, this can be solved with a humble "cut" too. &lt;BR /&gt;&lt;BR /&gt;"sed" would also work, but sed solutions all too easily become painfully Write-Only :-)&lt;BR /&gt;&lt;BR /&gt;Is the account ID always prefixed by "/c14/v23.129/" or can this vary too? Since this looks like a version number, I'll assume the numbers might vary, but the number of path elements will stay the same.&lt;BR /&gt;&lt;BR /&gt;If the prefix can vary, is it guaranteed that there request URI will have no spaces and a total of three slashes before the account ID? And that the account ID is always terminated with a slash?&lt;BR /&gt;&lt;BR /&gt;If so, then pipe your log to this little script: (i.e. execute with "scriptname &amp;lt; weblog.log")&lt;BR /&gt;&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;&lt;BR /&gt;while read logline&lt;BR /&gt;do&lt;BR /&gt;    ipaddr=$(echo "$logline" | cut -d " " -f 1&lt;BR /&gt;    requestURI=$(echo "$logline" | cut -d " " -f 7)&lt;BR /&gt;    accountID=$(echo "$requestURI" | cut -d / -f 4)&lt;BR /&gt;    echo "Account $accountID from IP $ipaddr"&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;MK</description>
      <pubDate>Mon, 05 Oct 2009 18:35:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-question/m-p/4508023#M681153</guid>
      <dc:creator>Matti_Kurkela</dc:creator>
      <dc:date>2009-10-05T18:35:39Z</dc:date>
    </item>
    <item>
      <title>Re: Awk question?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-question/m-p/4508024#M681154</link>
      <description>Thanks Hein!&lt;BR /&gt;&lt;BR /&gt;Works even with \s.* while omitting the ?.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Allan</description>
      <pubDate>Mon, 05 Oct 2009 20:18:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-question/m-p/4508024#M681154</guid>
      <dc:creator>Allanm</dc:creator>
      <dc:date>2009-10-05T20:18:14Z</dc:date>
    </item>
    <item>
      <title>Re: Awk question?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-question/m-p/4508025#M681155</link>
      <description>JRF , can explain the regex ...&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Allan.</description>
      <pubDate>Mon, 05 Oct 2009 20:19:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-question/m-p/4508025#M681155</guid>
      <dc:creator>Allanm</dc:creator>
      <dc:date>2009-10-05T20:19:06Z</dc:date>
    </item>
    <item>
      <title>Re: Awk question?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-question/m-p/4508026#M681156</link>
      <description>Hi (again) Allan"&lt;BR /&gt;&lt;BR /&gt;&amp;gt; JRF , can explain the regex ...&lt;BR /&gt;&lt;BR /&gt;# perl -nle '/((?:\d+\.?)+).+rptid=(\d+)/ and print join ":",$1,$2' file&lt;BR /&gt;&lt;BR /&gt;Match and capture one or more digits (\d+) followed by an optional dot character (\.); repeating one more times; followed by any number of characters and the pattern "rptid=".  The inner parentheses are non-capturing (?:) ones since we don't need them for anything other than a group repetition.  Thus the address is captured in $1.  Following the "rptid=" pattern we capture one or more digits that follow in $2.&lt;BR /&gt;&lt;BR /&gt;If the whole pattern is satisfied, we print the pieces that were stored in $1 and $2, joining them together with a colon character.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Mon, 05 Oct 2009 20:45:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-question/m-p/4508026#M681156</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-10-05T20:45:30Z</dc:date>
    </item>
    <item>
      <title>Re: Awk question?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-question/m-p/4508027#M681157</link>
      <description>This looks like a continuation of your other threads:&lt;BR /&gt;&lt;A href="http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1375401" target="_blank"&gt;http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1375401&lt;/A&gt;</description>
      <pubDate>Tue, 06 Oct 2009 13:46:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-question/m-p/4508027#M681157</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2009-10-06T13:46:59Z</dc:date>
    </item>
    <item>
      <title>Re: Awk question?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-question/m-p/4508028#M681158</link>
      <description>Hi (again) Allan:&lt;BR /&gt;&lt;BR /&gt;So Dennis was correct, your requirements were better defined in you earlier thread :-) namely "The account id will always be the 3rd entry from /(slash) - with t15 being server-number, v33.109- code version and 670612718 being the account id."&lt;BR /&gt;&lt;BR /&gt;Given this, I would offer:&lt;BR /&gt;&lt;BR /&gt;# perl -nle 'm{^((?:\d+\.?){4}).+"GET\s+/.+?/.+?/(\d+)} and print join ":",$1,$2'&lt;BR /&gt;&lt;BR /&gt;This also anchors the the isolation of the IPaddress to the beginning of each line.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Tue, 06 Oct 2009 14:07:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-question/m-p/4508028#M681158</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-10-06T14:07:35Z</dc:date>
    </item>
    <item>
      <title>Re: Awk question?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-question/m-p/4508029#M681159</link>
      <description>For the given data:&lt;BR /&gt;&lt;BR /&gt;$ awk -F '[ - / ]' '{print $1,$12}' wlog&lt;BR /&gt;1.1.1.1 011157032&lt;BR /&gt;</description>
      <pubDate>Wed, 07 Oct 2009 06:09:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-question/m-p/4508029#M681159</guid>
      <dc:creator>user57</dc:creator>
      <dc:date>2009-10-07T06:09:35Z</dc:date>
    </item>
    <item>
      <title>Re: Awk question?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-question/m-p/4508030#M681160</link>
      <description>You did want an awk solution. For a 2 line file:&lt;BR /&gt;&lt;BR /&gt;awk -F \" '&lt;BR /&gt;{&lt;BR /&gt;split($1,IP,"-")&lt;BR /&gt;split($2,ID,"/")&lt;BR /&gt;print IP[1],ID[4]&lt;BR /&gt;}' wlog&lt;BR /&gt;&lt;BR /&gt;./web.awk&lt;BR /&gt;1.1.1.1  011157032&lt;BR /&gt;1.1.1.2  011157033&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 07 Oct 2009 11:18:13 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-question/m-p/4508030#M681160</guid>
      <dc:creator>user57</dc:creator>
      <dc:date>2009-10-07T11:18:13Z</dc:date>
    </item>
  </channel>
</rss>

