<?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: getting info between 2 fields in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/getting-info-between-2-fields/m-p/5069670#M94855</link>
    <description>now that i think about it a bit more&lt;BR /&gt;this should work just as well&lt;BR /&gt;&lt;BR /&gt;awk '&lt;BR /&gt;{label = (label $0);}&lt;BR /&gt;/^LABEL/ {label = $0;}&lt;BR /&gt;/the date/ {date = "found";}&lt;BR /&gt;/^SENSE/ {if (date ~ "found" ) &lt;BR /&gt;{printf("%s",label);&lt;BR /&gt;date = "done";}&lt;BR /&gt;}'</description>
    <pubDate>Wed, 19 Sep 2007 12:23:20 GMT</pubDate>
    <dc:creator>larsoncu</dc:creator>
    <dc:date>2007-09-19T12:23:20Z</dc:date>
    <item>
      <title>getting info between 2 fields</title>
      <link>https://community.hpe.com/t5/operating-system-linux/getting-info-between-2-fields/m-p/5069662#M94847</link>
      <description>Hello all,&lt;BR /&gt;&lt;BR /&gt;I am attempting to get all information between two strings when a certain field is equal to  Wed Sep 19.&lt;BR /&gt;&lt;BR /&gt;here is an example of the data in the file (nb this is on AIX O/S)&lt;BR /&gt;&lt;BR /&gt;LABEL:          VPATH_PATH_OPEN&lt;BR /&gt;IDENTIFIER:     F45CFAFB&lt;BR /&gt;&lt;BR /&gt;Date/Time:       Wed Sep 19 15:00:23 BST 2007&lt;BR /&gt;Sequence Number: 316081&lt;BR /&gt;Machine Id:      00C84A6D4C00&lt;BR /&gt;Node Id:         pace&lt;BR /&gt;Class:           H&lt;BR /&gt;Type:            PERM&lt;BR /&gt;Resource Name:   hdisk22&lt;BR /&gt;Resource Class:  disk&lt;BR /&gt;Resource Type:   2107&lt;BR /&gt;Location:        U787B.001.DNW3DCD-P1-C2-T1-W500507630518C473-L4031400800000000&lt;BR /&gt;VPD:&lt;BR /&gt;        Manufacturer................IBM&lt;BR /&gt;        Machine Type and Model......2107900&lt;BR /&gt;        Serial Number...............75FDFW13108&lt;BR /&gt;        EC Level.....................309&lt;BR /&gt;        Device Specific.(Z0)........10&lt;BR /&gt;        Device Specific.(Z1)........0303&lt;BR /&gt;        Device Specific.(Z2)........075&lt;BR /&gt;        Device Specific.(Z3)........30806&lt;BR /&gt;        Device Specific.(Z4)........08&lt;BR /&gt;        Device Specific.(Z5)........00&lt;BR /&gt;&lt;BR /&gt;Description&lt;BR /&gt;OPEN FAILURE&lt;BR /&gt;&lt;BR /&gt;Probable Causes&lt;BR /&gt;DISK&lt;BR /&gt;SCSI ADAPTER&lt;BR /&gt;SCSI CABLE&lt;BR /&gt;&lt;BR /&gt;Failure Causes&lt;BR /&gt;DISK&lt;BR /&gt;SCSI ADAPTER&lt;BR /&gt;CABLE LOOSE OR DEFECTIVE&lt;BR /&gt;&lt;BR /&gt;        Recommended Actions&lt;BR /&gt;        PERFORM PROBLEM DETERMINATION ON SCSI TARGET DEVICE&lt;BR /&gt;        PERFORM PROBLEM DETERMINATION ON HOST SCSI ADAPTER&lt;BR /&gt;                REPLACE SCSI CABLE&lt;BR /&gt;&lt;BR /&gt;Detail Data&lt;BR /&gt;SENSE DATA&lt;BR /&gt;0000 0000 8000 002A 0000 0012 0000 0003 0000 0001 0000 0000 0000 0005&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;so when todays date is found I would like to print all information between LABEL: and SENSE DATA.&lt;BR /&gt;&lt;BR /&gt;any help will be greatly appreciated.&lt;BR /&gt;&lt;BR /&gt;Thanks Chris.</description>
      <pubDate>Wed, 19 Sep 2007 09:29:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/getting-info-between-2-fields/m-p/5069662#M94847</guid>
      <dc:creator>lawrenzo_1</dc:creator>
      <dc:date>2007-09-19T09:29:50Z</dc:date>
    </item>
    <item>
      <title>Re: getting info between 2 fields</title>
      <link>https://community.hpe.com/t5/operating-system-linux/getting-info-between-2-fields/m-p/5069663#M94848</link>
      <description>I have made a start but am struggling to get it to print between the search string:&lt;BR /&gt;&lt;BR /&gt;errpt -a |awk -F":" '/Date\/Time/ {if ($2 ~ /Wed Sep 19/) {print}}'&lt;BR /&gt;&lt;BR /&gt;thanks again</description>
      <pubDate>Wed, 19 Sep 2007 09:43:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/getting-info-between-2-fields/m-p/5069663#M94848</guid>
      <dc:creator>lawrenzo_1</dc:creator>
      <dc:date>2007-09-19T09:43:46Z</dc:date>
    </item>
    <item>
      <title>Re: getting info between 2 fields</title>
      <link>https://community.hpe.com/t5/operating-system-linux/getting-info-between-2-fields/m-p/5069664#M94849</link>
      <description>Hy&lt;BR /&gt;&lt;BR /&gt;If you found the date use this.&lt;BR /&gt;&lt;BR /&gt;START="LABEL"&lt;BR /&gt;END="SENSE DATA"&lt;BR /&gt;read=0&lt;BR /&gt;&lt;BR /&gt;for line in $(cat yourfile) ; do&lt;BR /&gt;&lt;BR /&gt;if [ "${line}" = "${START}" ]&lt;BR /&gt; read=1&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;if [ ${read} -eq 1 ]&lt;BR /&gt;then&lt;BR /&gt;  echo ${line}&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;if [ "${line}" = "${END}" ]&lt;BR /&gt; read=0&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;not tested just a brain dump&lt;BR /&gt;&lt;BR /&gt;Regards</description>
      <pubDate>Wed, 19 Sep 2007 10:18:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/getting-info-between-2-fields/m-p/5069664#M94849</guid>
      <dc:creator>Oviwan</dc:creator>
      <dc:date>2007-09-19T10:18:42Z</dc:date>
    </item>
    <item>
      <title>Re: getting info between 2 fields</title>
      <link>https://community.hpe.com/t5/operating-system-linux/getting-info-between-2-fields/m-p/5069665#M94850</link>
      <description>this should get you pretty close&lt;BR /&gt;&lt;BR /&gt;awk '&lt;BR /&gt;/^LABEL/ {label= $0;}&lt;BR /&gt;/the date/ {printf("%s",label); print $0; date="found";}&lt;BR /&gt;{label =. $0; if (date ~ "found" ) print $0;}&lt;BR /&gt;/^SENSE/ {print $0;date = "done";}</description>
      <pubDate>Wed, 19 Sep 2007 11:57:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/getting-info-between-2-fields/m-p/5069665#M94850</guid>
      <dc:creator>larsoncu</dc:creator>
      <dc:date>2007-09-19T11:57:09Z</dc:date>
    </item>
    <item>
      <title>Re: getting info between 2 fields</title>
      <link>https://community.hpe.com/t5/operating-system-linux/getting-info-between-2-fields/m-p/5069666#M94851</link>
      <description>&lt;!--!*#--&gt;Hi Chris:&lt;BR /&gt;&lt;BR /&gt;Try thisL:&lt;BR /&gt;&lt;BR /&gt;# cat ./filter&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;use strict;&lt;BR /&gt;use warnings;&lt;BR /&gt;&lt;BR /&gt;my @a;&lt;BR /&gt;my $toggle = 0;&lt;BR /&gt;my $target = shift;&lt;BR /&gt;&lt;BR /&gt;while (&amp;lt;&amp;gt;) {&lt;BR /&gt;    push @a, $_ if /^LABEL|^IDENTIFIER|^\s*$/;&lt;BR /&gt;&lt;BR /&gt;    if (/^Date/) {&lt;BR /&gt;        if (/$target/) {&lt;BR /&gt;            $toggle++;&lt;BR /&gt;            print for @a;&lt;BR /&gt;            @a = ();&lt;BR /&gt;        }&lt;BR /&gt;        else {&lt;BR /&gt;            $toggle = 0;&lt;BR /&gt;            @a      = ();&lt;BR /&gt;        }&lt;BR /&gt;    }&lt;BR /&gt;    if ($toggle) {&lt;BR /&gt;        if (/^SENSE/) {&lt;BR /&gt;            print;&lt;BR /&gt;            $_ = &amp;lt;&amp;gt;;&lt;BR /&gt;            print;&lt;BR /&gt;            $toggle = 0;&lt;BR /&gt;        }&lt;BR /&gt;        else {&lt;BR /&gt;            print;&lt;BR /&gt;        }&lt;BR /&gt;    }&lt;BR /&gt;}&lt;BR /&gt;1;&lt;BR /&gt;&lt;BR /&gt;...Run this passing two arguments.  The first is a QUOTED (single or double) string defining your target date.  The second argument is the name of the file containing the data to be parsed:&lt;BR /&gt;&lt;BR /&gt;# ./filter 'Sep 19' logfile&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Wed, 19 Sep 2007 12:01:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/getting-info-between-2-fields/m-p/5069666#M94851</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-09-19T12:01:47Z</dc:date>
    </item>
    <item>
      <title>Re: getting info between 2 fields</title>
      <link>https://community.hpe.com/t5/operating-system-linux/getting-info-between-2-fields/m-p/5069667#M94852</link>
      <description>this should work just as well&lt;BR /&gt;&lt;BR /&gt;awk '&lt;BR /&gt;/^LABEL/ {label= $0;}&lt;BR /&gt;/the date/ {label =. $0;date = "found"}&lt;BR /&gt;{label =. $0;}&lt;BR /&gt;/^SENSE/ {label =. $0;if (date ~ "found" ) {printf("%s",label);date = "done";}&lt;BR /&gt;}'</description>
      <pubDate>Wed, 19 Sep 2007 12:02:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/getting-info-between-2-fields/m-p/5069667#M94852</guid>
      <dc:creator>larsoncu</dc:creator>
      <dc:date>2007-09-19T12:02:36Z</dc:date>
    </item>
    <item>
      <title>Re: getting info between 2 fields</title>
      <link>https://community.hpe.com/t5/operating-system-linux/getting-info-between-2-fields/m-p/5069668#M94853</link>
      <description>Hi Chris,&lt;BR /&gt;&lt;BR /&gt;my solution uses the strings LABEL and SENSE DATA as block markers. I store all upto the date/time line in an array, which is printed when there is a match, the rest of the block is directly printed.&lt;BR /&gt;The matching pattern is generated by the date command and fed into an awk variable.&lt;BR /&gt;&lt;BR /&gt;awk -v m="$(date '+%b %d .* %Y')" '/^LABEL/ {what=-1;next}&lt;BR /&gt;what&amp;lt;0 {keep[lino++]=$0}&lt;BR /&gt;/^Date\/Time: / {if($0 ~ m) {what=1;for(i=0;i&lt;LINO&gt;&lt;/LINO&gt;else {what=0;lino=0} }&lt;BR /&gt;/^SENSE DATA/ {what=0;lino=0}&lt;BR /&gt;what&amp;gt;0' /tmp/inputdata&lt;BR /&gt;&lt;BR /&gt;I would prefer to skip the line 'Detail Data' additionally - just replace&lt;BR /&gt;/^SENSE DATA/ {what=0;lino=0}&lt;BR /&gt;by&lt;BR /&gt;/^Detail Data {what=0;lino=0}&lt;BR /&gt;&lt;BR /&gt;mfG Peter</description>
      <pubDate>Wed, 19 Sep 2007 12:08:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/getting-info-between-2-fields/m-p/5069668#M94853</guid>
      <dc:creator>Peter Nikitka</dc:creator>
      <dc:date>2007-09-19T12:08:11Z</dc:date>
    </item>
    <item>
      <title>Re: getting info between 2 fields</title>
      <link>https://community.hpe.com/t5/operating-system-linux/getting-info-between-2-fields/m-p/5069669#M94854</link>
      <description>oops guess i'm mixing my perl and awk up.&lt;BR /&gt;anyway there is no =. in awk.&lt;BR /&gt;&lt;BR /&gt;you'll need to replace the concatenations like this:&lt;BR /&gt;label =. $0;&lt;BR /&gt;&lt;BR /&gt;should be:&lt;BR /&gt;label = (label $0);</description>
      <pubDate>Wed, 19 Sep 2007 12:15:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/getting-info-between-2-fields/m-p/5069669#M94854</guid>
      <dc:creator>larsoncu</dc:creator>
      <dc:date>2007-09-19T12:15:09Z</dc:date>
    </item>
    <item>
      <title>Re: getting info between 2 fields</title>
      <link>https://community.hpe.com/t5/operating-system-linux/getting-info-between-2-fields/m-p/5069670#M94855</link>
      <description>now that i think about it a bit more&lt;BR /&gt;this should work just as well&lt;BR /&gt;&lt;BR /&gt;awk '&lt;BR /&gt;{label = (label $0);}&lt;BR /&gt;/^LABEL/ {label = $0;}&lt;BR /&gt;/the date/ {date = "found";}&lt;BR /&gt;/^SENSE/ {if (date ~ "found" ) &lt;BR /&gt;{printf("%s",label);&lt;BR /&gt;date = "done";}&lt;BR /&gt;}'</description>
      <pubDate>Wed, 19 Sep 2007 12:23:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/getting-info-between-2-fields/m-p/5069670#M94855</guid>
      <dc:creator>larsoncu</dc:creator>
      <dc:date>2007-09-19T12:23:20Z</dc:date>
    </item>
    <item>
      <title>Re: getting info between 2 fields</title>
      <link>https://community.hpe.com/t5/operating-system-linux/getting-info-between-2-fields/m-p/5069671#M94856</link>
      <description>&lt;!--!*#--&gt;Yet another way of doing the same thing.&lt;BR /&gt;&lt;BR /&gt;awk '&lt;BR /&gt;{&lt;BR /&gt;  if ($0~dt) flg++&lt;BR /&gt;  if ($0~"LABEL:") start++&lt;BR /&gt;  if ($0~"SENSE DATA")&lt;BR /&gt;  {&lt;BR /&gt;    if (flg) {print lst;lst="";flg=0;start=0}&lt;BR /&gt;    else {lst="";start=0}&lt;BR /&gt;  }&lt;BR /&gt;  if (start) lst=(lst?lst"\n"$0:$0)&lt;BR /&gt;}' dt="$(date +"%a %b %d")" file</description>
      <pubDate>Wed, 19 Sep 2007 18:53:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/getting-info-between-2-fields/m-p/5069671#M94856</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2007-09-19T18:53:46Z</dc:date>
    </item>
    <item>
      <title>Re: getting info between 2 fields</title>
      <link>https://community.hpe.com/t5/operating-system-linux/getting-info-between-2-fields/m-p/5069672#M94857</link>
      <description>thanks all for the exellent examples,&lt;BR /&gt;&lt;BR /&gt;I will be able to adapt this for plenty of scenarios.&lt;BR /&gt;&lt;BR /&gt;Chris.</description>
      <pubDate>Thu, 20 Sep 2007 02:52:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/getting-info-between-2-fields/m-p/5069672#M94857</guid>
      <dc:creator>lawrenzo_1</dc:creator>
      <dc:date>2007-09-20T02:52:42Z</dc:date>
    </item>
    <item>
      <title>Re: getting info between 2 fields</title>
      <link>https://community.hpe.com/t5/operating-system-linux/getting-info-between-2-fields/m-p/5069673#M94858</link>
      <description>&lt;!--!*#--&gt;If you assume the first 4 lines are LABEL, ID, blank and date you can do:&lt;BR /&gt;awk -v date="Wed Sep 19" '&lt;BR /&gt;BEGIN { skip = 1 }&lt;BR /&gt;/^LABEL/ {&lt;BR /&gt;   save1 = $0&lt;BR /&gt;   getline&lt;BR /&gt;   save2 = $0&lt;BR /&gt;   getline  # assume blank&lt;BR /&gt;   getline&lt;BR /&gt;   if ($2 " " $3 " " $4 == date) {&lt;BR /&gt;      print save1&lt;BR /&gt;      print save2&lt;BR /&gt;      print $0&lt;BR /&gt;      skip = 0&lt;BR /&gt;   }&lt;BR /&gt;   next&lt;BR /&gt;}&lt;BR /&gt;/^SENSE DATA/ {&lt;BR /&gt;   # dont print this line&lt;BR /&gt;   skip = 1&lt;BR /&gt;   next&lt;BR /&gt;}&lt;BR /&gt;{  if (!skip) print $0&lt;BR /&gt;} ' input_file</description>
      <pubDate>Thu, 20 Sep 2007 03:20:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/getting-info-between-2-fields/m-p/5069673#M94858</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2007-09-20T03:20:08Z</dc:date>
    </item>
  </channel>
</rss>

