<?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 Awk:  split into fields, and then split again in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-split-into-fields-and-then-split-again/m-p/3296609#M715741</link>
    <description>Good day!&lt;BR /&gt;&lt;BR /&gt;I have text files formatted like this:&lt;BR /&gt;&lt;BR /&gt;===================================================&lt;BR /&gt;Logging begins at:  [2004.05.31 00:24:20]&lt;BR /&gt;r [2004.05.31 00:24:34] (348) reason1:  more text: foofoo   STRING2:  [9.8.7.5] &lt;BR /&gt;r [2004.05.31 00:24:47] (325) reason1:  more text: var bar car   STRING: txt.info.dot [4.3.2.1] &lt;BR /&gt;r [2004.05.31 00:25:20] (476) other reason  text: variable lenght   ZZZZZ: stuff.i.want.now [5.6.7.8] &lt;BR /&gt;r [2004.05.31 00:25:20] (391) reason1:  some other text: foo  BAR: stuff.wanted.txt [1.2.3.4]  various text of various length&lt;BR /&gt;[and so on]&lt;BR /&gt;&lt;BR /&gt;I can pull out the portion in the second square brackets with AWK like this:&lt;BR /&gt;&lt;BR /&gt;&amp;gt; BEGIN { FS="[][]" }&lt;BR /&gt;&amp;gt; {print $4}&lt;BR /&gt;&lt;BR /&gt;(NB:  FS="[[]]" does not work!)&lt;BR /&gt;&lt;BR /&gt;Now, what I'd like to do is split the $3 portion, colon-delimited, and get the last field.    In the text above, that would be:&lt;BR /&gt;&lt;BR /&gt;(blank)&lt;BR /&gt;txt.info.dot &lt;BR /&gt;stuff.i.want.now &lt;BR /&gt;stuff.wanted.txt&lt;BR /&gt;&lt;BR /&gt;Then I'd like to print $4, (new_$3) like this&lt;BR /&gt;&lt;BR /&gt;[1.2.3.4] (stuff.wanted.txt)&lt;BR /&gt;&lt;BR /&gt;I've looked in the slender loris book, comp.lang.awk, and here, but either I am not searching properly or I'm to ignorant to understand what I'm reading.&lt;BR /&gt;&lt;BR /&gt;Awk preferred; perl answers are nice, but no "one-liners," please.  :-)&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;&lt;BR /&gt;Rob</description>
    <pubDate>Fri, 04 Jun 2004 14:37:42 GMT</pubDate>
    <dc:creator>Robert A. Pierce</dc:creator>
    <dc:date>2004-06-04T14:37:42Z</dc:date>
    <item>
      <title>Awk:  split into fields, and then split again</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-split-into-fields-and-then-split-again/m-p/3296609#M715741</link>
      <description>Good day!&lt;BR /&gt;&lt;BR /&gt;I have text files formatted like this:&lt;BR /&gt;&lt;BR /&gt;===================================================&lt;BR /&gt;Logging begins at:  [2004.05.31 00:24:20]&lt;BR /&gt;r [2004.05.31 00:24:34] (348) reason1:  more text: foofoo   STRING2:  [9.8.7.5] &lt;BR /&gt;r [2004.05.31 00:24:47] (325) reason1:  more text: var bar car   STRING: txt.info.dot [4.3.2.1] &lt;BR /&gt;r [2004.05.31 00:25:20] (476) other reason  text: variable lenght   ZZZZZ: stuff.i.want.now [5.6.7.8] &lt;BR /&gt;r [2004.05.31 00:25:20] (391) reason1:  some other text: foo  BAR: stuff.wanted.txt [1.2.3.4]  various text of various length&lt;BR /&gt;[and so on]&lt;BR /&gt;&lt;BR /&gt;I can pull out the portion in the second square brackets with AWK like this:&lt;BR /&gt;&lt;BR /&gt;&amp;gt; BEGIN { FS="[][]" }&lt;BR /&gt;&amp;gt; {print $4}&lt;BR /&gt;&lt;BR /&gt;(NB:  FS="[[]]" does not work!)&lt;BR /&gt;&lt;BR /&gt;Now, what I'd like to do is split the $3 portion, colon-delimited, and get the last field.    In the text above, that would be:&lt;BR /&gt;&lt;BR /&gt;(blank)&lt;BR /&gt;txt.info.dot &lt;BR /&gt;stuff.i.want.now &lt;BR /&gt;stuff.wanted.txt&lt;BR /&gt;&lt;BR /&gt;Then I'd like to print $4, (new_$3) like this&lt;BR /&gt;&lt;BR /&gt;[1.2.3.4] (stuff.wanted.txt)&lt;BR /&gt;&lt;BR /&gt;I've looked in the slender loris book, comp.lang.awk, and here, but either I am not searching properly or I'm to ignorant to understand what I'm reading.&lt;BR /&gt;&lt;BR /&gt;Awk preferred; perl answers are nice, but no "one-liners," please.  :-)&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;&lt;BR /&gt;Rob</description>
      <pubDate>Fri, 04 Jun 2004 14:37:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-split-into-fields-and-then-split-again/m-p/3296609#M715741</guid>
      <dc:creator>Robert A. Pierce</dc:creator>
      <dc:date>2004-06-04T14:37:42Z</dc:date>
    </item>
    <item>
      <title>Re: Awk:  split into fields, and then split again</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-split-into-fields-and-then-split-again/m-p/3296610#M715742</link>
      <description>Can't you just set the delimeter?&lt;BR /&gt;&lt;BR /&gt;awk -F:&lt;BR /&gt;&lt;BR /&gt;Rgds...Geoff</description>
      <pubDate>Fri, 04 Jun 2004 14:44:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-split-into-fields-and-then-split-again/m-p/3296610#M715742</guid>
      <dc:creator>Geoff Wild</dc:creator>
      <dc:date>2004-06-04T14:44:16Z</dc:date>
    </item>
    <item>
      <title>Re: Awk:  split into fields, and then split again</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-split-into-fields-and-then-split-again/m-p/3296611#M715743</link>
      <description>split your line into an array&lt;BR /&gt;&lt;BR /&gt;split($0,a,":");&lt;BR /&gt;&lt;BR /&gt;then split array element&lt;BR /&gt;&lt;BR /&gt;split(a[4],b,"[");&lt;BR /&gt;&lt;BR /&gt;print b[1];</description>
      <pubDate>Fri, 04 Jun 2004 14:46:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-split-into-fields-and-then-split-again/m-p/3296611#M715743</guid>
      <dc:creator>curt larson_1</dc:creator>
      <dc:date>2004-06-04T14:46:20Z</dc:date>
    </item>
    <item>
      <title>Re: Awk:  split into fields, and then split again</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-split-into-fields-and-then-split-again/m-p/3296612#M715744</link>
      <description>&lt;BR /&gt;So, would you do something like&lt;BR /&gt;&lt;BR /&gt;BEGIN { FS="[][]" }&lt;BR /&gt;&lt;BR /&gt;{&lt;BR /&gt;print $4&lt;BR /&gt;temp=$3&lt;BR /&gt;FS=:&lt;BR /&gt;print "("$NF")\n"&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;I wasn't able to get that to work.&lt;BR /&gt;&lt;BR /&gt;what am I missing?</description>
      <pubDate>Fri, 04 Jun 2004 14:48:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-split-into-fields-and-then-split-again/m-p/3296612#M715744</guid>
      <dc:creator>Robert A. Pierce</dc:creator>
      <dc:date>2004-06-04T14:48:53Z</dc:date>
    </item>
    <item>
      <title>Re: Awk:  split into fields, and then split again</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-split-into-fields-and-then-split-again/m-p/3296613#M715745</link>
      <description>of course it does seem to be easier if you use colon as your field seperator&lt;BR /&gt;&lt;BR /&gt;awk -F: '{&lt;BR /&gt;split($4,a,"[");&lt;BR /&gt;printf("[%s,%s\n",a[2],a[1]);&lt;BR /&gt;}'</description>
      <pubDate>Fri, 04 Jun 2004 14:50:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-split-into-fields-and-then-split-again/m-p/3296613#M715745</guid>
      <dc:creator>curt larson_1</dc:creator>
      <dc:date>2004-06-04T14:50:43Z</dc:date>
    </item>
    <item>
      <title>Re: Awk:  split into fields, and then split again</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-split-into-fields-and-then-split-again/m-p/3296614#M715746</link>
      <description>robert,&lt;BR /&gt;&lt;BR /&gt;BEGIN { FS="[][]" }&lt;BR /&gt;&lt;BR /&gt;{&lt;BR /&gt;print $4&lt;BR /&gt;temp=$3&lt;BR /&gt;FS=:&lt;BR /&gt;print "("$NF")\n"&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;I wasn't able to get that to work.&lt;BR /&gt;&lt;BR /&gt;what am I missing? &lt;BR /&gt;&lt;BR /&gt;no semicolon at the end of statement&lt;BR /&gt;print $4;&lt;BR /&gt;temp=$3;&lt;BR /&gt;etc</description>
      <pubDate>Fri, 04 Jun 2004 14:52:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-split-into-fields-and-then-split-again/m-p/3296614#M715746</guid>
      <dc:creator>curt larson_1</dc:creator>
      <dc:date>2004-06-04T14:52:48Z</dc:date>
    </item>
    <item>
      <title>Re: Awk:  split into fields, and then split again</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-split-into-fields-and-then-split-again/m-p/3296615#M715747</link>
      <description>robert,&lt;BR /&gt;&lt;BR /&gt;not sure what your trying to do with this:&lt;BR /&gt;print "("$NF")\n"&lt;BR /&gt;&lt;BR /&gt;print number of fields:&lt;BR /&gt;print NF;&lt;BR /&gt;&lt;BR /&gt;print the last field:&lt;BR /&gt;print $NF;&lt;BR /&gt;&lt;BR /&gt;usually i think what you want is to do this&lt;BR /&gt;printf("%s\n",$NF);</description>
      <pubDate>Fri, 04 Jun 2004 14:55:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-split-into-fields-and-then-split-again/m-p/3296615#M715747</guid>
      <dc:creator>curt larson_1</dc:creator>
      <dc:date>2004-06-04T14:55:55Z</dc:date>
    </item>
    <item>
      <title>Re: Awk:  split into fields, and then split again</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-split-into-fields-and-then-split-again/m-p/3296616#M715748</link>
      <description>Curt,&lt;BR /&gt;&lt;BR /&gt;BEGIN { FS="[][]" }&lt;BR /&gt;&lt;BR /&gt;{&lt;BR /&gt;print $4&lt;BR /&gt;&lt;BR /&gt;sizeOfArray =split($3,name,":");&lt;BR /&gt;print name[sizeOfArray]; &lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;Works mostly!  &lt;BR /&gt;&lt;BR /&gt;On some records it's returning too much; let me see why . . . .</description>
      <pubDate>Fri, 04 Jun 2004 14:56:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-split-into-fields-and-then-split-again/m-p/3296616#M715748</guid>
      <dc:creator>Robert A. Pierce</dc:creator>
      <dc:date>2004-06-04T14:56:28Z</dc:date>
    </item>
    <item>
      <title>Re: Awk:  split into fields, and then split again</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-split-into-fields-and-then-split-again/m-p/3296617#M715749</link>
      <description>&lt;BR /&gt;I'm not using the colon at first, because there is a variable number of colons involved.  &lt;BR /&gt;&lt;BR /&gt;The constants are:  the SECOND square-bracketed field, and the LAST colon-delimited field prior to that 2nd [] field.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 04 Jun 2004 15:00:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-split-into-fields-and-then-split-again/m-p/3296617#M715749</guid>
      <dc:creator>Robert A. Pierce</dc:creator>
      <dc:date>2004-06-04T15:00:03Z</dc:date>
    </item>
    <item>
      <title>Re: Awk:  split into fields, and then split again</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-split-into-fields-and-then-split-again/m-p/3296618#M715750</link>
      <description>This works:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;BEGIN { FS="[][]" }&lt;BR /&gt;&lt;BR /&gt;match($1,"^r") &amp;gt;0  {&lt;BR /&gt;&lt;BR /&gt;sizeOfArray =split($3,name,":");&lt;BR /&gt;print $4" ("name[sizeOfArray]")";&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;The split() is what did it.&lt;BR /&gt;&lt;BR /&gt;Thanks to all who replied!&lt;BR /&gt;&lt;BR /&gt;Rob</description>
      <pubDate>Fri, 04 Jun 2004 15:12:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-split-into-fields-and-then-split-again/m-p/3296618#M715750</guid>
      <dc:creator>Robert A. Pierce</dc:creator>
      <dc:date>2004-06-04T15:12:03Z</dc:date>
    </item>
  </channel>
</rss>

