<?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 lines from a report - ksh in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/getting-lines-from-a-report-ksh/m-p/4656473#M677182</link>
    <description>forgot to add...&lt;BR /&gt;&lt;BR /&gt;The test for job != "" and the clearing of job after print is in order to protect against additional blank lines or random blob of text in the report. &lt;BR /&gt;&lt;BR /&gt;if the input is exactly as you describe, then this will be enough:&lt;BR /&gt;&lt;BR /&gt;$ awk 'NR &amp;lt; 3; /^Job:/ {print "\n" $0}; !NF {print last} { last = $0}' report&lt;BR /&gt;Report 07 Job History Listing 06/02/10&lt;BR /&gt;Date Time Schedule Name Elapsed CPU Status&lt;BR /&gt;&lt;BR /&gt;Job:PDWH06UX #PPYHP_DWH_ECS_NACRLAN_M&lt;BR /&gt;06/01/10 15:37 PDWH06UX #JOBS5 1 1&lt;BR /&gt;&lt;BR /&gt;Job:PDWH06UX #PPYHP_DWH_ECS_QUL1_D&lt;BR /&gt;06/01/10 06:40 PDWH06UX #PPYHP_DWH_ECS_D 1 1&lt;BR /&gt;&lt;BR /&gt;Job:PDWH06UX #PPYHP_DWH_ECS_PYJFPLOG_D&lt;BR /&gt;06/01/10 15:32 PDWH06UX #JOBS8 1 1&lt;BR /&gt;&lt;BR /&gt;Hein&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Sat, 03 Jul 2010 18:35:05 GMT</pubDate>
    <dc:creator>Hein van den Heuvel</dc:creator>
    <dc:date>2010-07-03T18:35:05Z</dc:date>
    <item>
      <title>Getting lines from a report - ksh</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/getting-lines-from-a-report-ksh/m-p/4656469#M677178</link>
      <description>I have this report, the space can be appear after 1,2,3 or more lines with information, in this example the&lt;BR /&gt;first Job has 5 lines of info, the, appears the space, the following job has only 1 line of info then&lt;BR /&gt;appears an space and go on ....&lt;BR /&gt;&lt;BR /&gt;Report 07    Job History Listing        06/02/10&lt;BR /&gt;           Date        Time    Schedule Name     Elapsed      CPU     Status&lt;BR /&gt;&lt;BR /&gt;line 1:  Job:PDWH06UX        #PPYHP_DWH_ECS_NACRLAN_M  &lt;BR /&gt;line 2:  06/01/10    15:05     PDWH06UX        #JOBS            1         1                &lt;BR /&gt;line 3:  06/01/10    15:33     PDWH06UX        #JOBS2            1         1         &lt;BR /&gt;line 4:  06/01/10    15:34     PDWH06UX        #JOBS3             1         1    &lt;BR /&gt;line 5:  06/01/10    15:36     PDWH06UX        #JOBS4            1         1    &lt;BR /&gt;line 6:  06/01/10    15:37     PDWH06UX        #JOBS5             1         1    &lt;BR /&gt;line 7:  &lt;BR /&gt;line 8:  Job:PDWH06UX        #PPYHP_DWH_ECS_QUL1_D       &lt;BR /&gt;line 9:  06/01/10    06:40     PDWH06UX        #PPYHP_DWH_ECS_D               1         1              &lt;BR /&gt;line 10:&lt;BR /&gt;line 11:  Job:PDWH06UX        #PPYHP_DWH_ECS_PYJFPLOG_D  &lt;BR /&gt;line 12:  06/01/10    06:38     PDWH06UX        #PPYHP_DWH_ECS_D             1         1                 &lt;BR /&gt;line 13:  06/01/10    07:28     PDWH06UX        #PPYHP_DWH_ECS_D2             1         1  &lt;BR /&gt;line 14:  06/01/10    15:32     PDWH06UX        #JOBS8            1         1                 &lt;BR /&gt;line 15:  &lt;BR /&gt;&lt;BR /&gt;i need to get a report as follows, first get the first line "Report 07 bla bla bla ", then to get the lline that says "Job" and getting the last line before the space ... &lt;BR /&gt;and the get again the line which says "job" and then to get the line before the space as follows &lt;BR /&gt;Report 07    Job History Listing        06/02/10     &lt;BR /&gt;           Date          Schedule Name     Elapsed      &lt;BR /&gt;line 1:  Job:PDWH06UX        #PPYHP_DWH_ECS_NACRLAN_M   &lt;BR /&gt;line 6:  06/01/10       PDWH06UX        #JOBS5            &lt;BR /&gt;line 7:(space)&lt;BR /&gt;line 8:  Job:PDWH06UX        #PPYHP_DWH_ECS_QUL1_D   &lt;BR /&gt;line 9:  06/01/10       PDWH06UX        #PPYHP_DWH_ECS_D  &lt;BR /&gt;line 10: (space)      &lt;BR /&gt;line 11:  Job:PDWH06UX        #PPYHP_DWH_ECS_PYJFPLOG_D&lt;BR /&gt;line 14:  06/01/10     PDWH06UX        #JOBS8       &lt;BR /&gt;&lt;BR /&gt;Thanks in advance.</description>
      <pubDate>Sat, 03 Jul 2010 17:28:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/getting-lines-from-a-report-ksh/m-p/4656469#M677178</guid>
      <dc:creator>Manuales</dc:creator>
      <dc:date>2010-07-03T17:28:40Z</dc:date>
    </item>
    <item>
      <title>Re: Getting lines from a report - ksh</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/getting-lines-from-a-report-ksh/m-p/4656470#M677179</link>
      <description>&lt;!--!*#--&gt;&amp;gt; i need to get a report [...]&lt;BR /&gt;&lt;BR /&gt;Are you getting paid to do this?&lt;BR /&gt;&lt;BR /&gt;Have you considered getting a book, or taking&lt;BR /&gt;a class, to learn how to write a computer&lt;BR /&gt;program?</description>
      <pubDate>Sat, 03 Jul 2010 17:51:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/getting-lines-from-a-report-ksh/m-p/4656470#M677179</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2010-07-03T17:51:06Z</dc:date>
    </item>
    <item>
      <title>Re: Getting lines from a report - ksh</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/getting-lines-from-a-report-ksh/m-p/4656471#M677180</link>
      <description>Hey .. this is part of my work.&lt;BR /&gt;I have done shells in ksh , i have used a little bit the awk but i do not know how to evaluate "if there is an space, keep previous line in a variable" &lt;BR /&gt;&lt;BR /&gt;can you help me with this:&lt;BR /&gt;"if there is an space, keep previous line in a variable"   &lt;BR /&gt;</description>
      <pubDate>Sat, 03 Jul 2010 18:21:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/getting-lines-from-a-report-ksh/m-p/4656471#M677180</guid>
      <dc:creator>Manuales</dc:creator>
      <dc:date>2010-07-03T18:21:36Z</dc:date>
    </item>
    <item>
      <title>Re: Getting lines from a report - ksh</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/getting-lines-from-a-report-ksh/m-p/4656472#M677181</link>
      <description>Steven, you gotta admit it was a much more clear problem description then most. That's a much appreciated step 1.&lt;BR /&gt;&lt;BR /&gt;Manuales...&lt;BR /&gt;&lt;BR /&gt;You about this awk 'one liner' or mini program:&lt;BR /&gt;&lt;BR /&gt;awk '(NR &amp;lt; 3)&lt;BR /&gt;/^Job:/ { job = $0 }&lt;BR /&gt;!NF &amp;amp;&amp;amp; job != "" { print; print job; print last; job="" }&lt;BR /&gt;{ last = $1 " " $3 " " $4}' report.txt&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;In slo mo...&lt;BR /&gt;&lt;BR /&gt;(NR &amp;lt; 3) : true for the first 2 lines. No action specified, so take default action is to print the input line.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;/^Job:/ { job = $0 } : If the line starts with Job: then save it in variable job&lt;BR /&gt;&lt;BR /&gt;!NF &amp;amp;&amp;amp; job != "" { print; print job; print last; job="" } : If there are NO fields on the line, and the variable job is not empty, then print a blank line, print job, and print a variable last which will hold data from the last non-blank line.&lt;BR /&gt;&lt;BR /&gt;{ last = $1 " " $3 " " $4} : any time, unconditionally, stash field 1, 3 and 4 in a variable last, just in case it really is the last line.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Enjoy,&lt;BR /&gt;Hein&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Sat, 03 Jul 2010 18:22:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/getting-lines-from-a-report-ksh/m-p/4656472#M677181</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2010-07-03T18:22:47Z</dc:date>
    </item>
    <item>
      <title>Re: Getting lines from a report - ksh</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/getting-lines-from-a-report-ksh/m-p/4656473#M677182</link>
      <description>forgot to add...&lt;BR /&gt;&lt;BR /&gt;The test for job != "" and the clearing of job after print is in order to protect against additional blank lines or random blob of text in the report. &lt;BR /&gt;&lt;BR /&gt;if the input is exactly as you describe, then this will be enough:&lt;BR /&gt;&lt;BR /&gt;$ awk 'NR &amp;lt; 3; /^Job:/ {print "\n" $0}; !NF {print last} { last = $0}' report&lt;BR /&gt;Report 07 Job History Listing 06/02/10&lt;BR /&gt;Date Time Schedule Name Elapsed CPU Status&lt;BR /&gt;&lt;BR /&gt;Job:PDWH06UX #PPYHP_DWH_ECS_NACRLAN_M&lt;BR /&gt;06/01/10 15:37 PDWH06UX #JOBS5 1 1&lt;BR /&gt;&lt;BR /&gt;Job:PDWH06UX #PPYHP_DWH_ECS_QUL1_D&lt;BR /&gt;06/01/10 06:40 PDWH06UX #PPYHP_DWH_ECS_D 1 1&lt;BR /&gt;&lt;BR /&gt;Job:PDWH06UX #PPYHP_DWH_ECS_PYJFPLOG_D&lt;BR /&gt;06/01/10 15:32 PDWH06UX #JOBS8 1 1&lt;BR /&gt;&lt;BR /&gt;Hein&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Sat, 03 Jul 2010 18:35:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/getting-lines-from-a-report-ksh/m-p/4656473#M677182</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2010-07-03T18:35:05Z</dc:date>
    </item>
    <item>
      <title>Re: Getting lines from a report - ksh</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/getting-lines-from-a-report-ksh/m-p/4656474#M677183</link>
      <description>Hi Hein, thank you so much ......&lt;BR /&gt;let me try right now, let me test it ....   :)</description>
      <pubDate>Sat, 03 Jul 2010 18:41:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/getting-lines-from-a-report-ksh/m-p/4656474#M677183</guid>
      <dc:creator>Manuales</dc:creator>
      <dc:date>2010-07-03T18:41:40Z</dc:date>
    </item>
    <item>
      <title>Re: Getting lines from a report - ksh</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/getting-lines-from-a-report-ksh/m-p/4656475#M677184</link>
      <description>Hein, really good explanation, thanks a lot for your GREAT support !!!!!!&lt;BR /&gt;&lt;BR /&gt;i was thinking in using a "for" to go evaluating line per line but i see here that i have to study more about AWK .. &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;really thanks again !!!!  :)  IT worked successfully  :).</description>
      <pubDate>Sat, 03 Jul 2010 19:10:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/getting-lines-from-a-report-ksh/m-p/4656475#M677184</guid>
      <dc:creator>Manuales</dc:creator>
      <dc:date>2010-07-03T19:10:21Z</dc:date>
    </item>
    <item>
      <title>Re: Getting lines from a report - ksh</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/getting-lines-from-a-report-ksh/m-p/4656476#M677185</link>
      <description>Hi Manauales:&lt;BR /&gt;&lt;BR /&gt;Here's another way:&lt;BR /&gt;&lt;BR /&gt;# perl -00 -ne '/^Report/ and print,next;/(^Job.+?$)(.*)(^\d.+$)/sm and print $1,"\n",$3' file&lt;BR /&gt;&lt;BR /&gt;This reads "paragraphs" of data at a time (-00).  If a paragraph begins wth "Report", print it in its entirety.  If a paragraph begins with "Job", then capture the string until a newline in $1 and don't be greedy about  it; grab zero or more characters in $2; and lastly stuff a line that begins with a digit (\d) into $3.  If we can make such a match, print what we captured in $1 and $3.&lt;BR /&gt;&lt;BR /&gt;Since we don't care about $2 (the lines beginning with a digit that aren't the last one in a group) we could/should skip their capture.  To do this we make a slight change and tell the regular expression engine that  we don't want to capture (?:) the second group ().&lt;BR /&gt;&lt;BR /&gt;# perl -00 -ne '/^Report/ and print,next;/(^Job.+?$)(?:.*)(^\d.+$)/sm and print $1,"\n",$2' file&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Sun, 04 Jul 2010 14:53:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/getting-lines-from-a-report-ksh/m-p/4656476#M677185</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2010-07-04T14:53:07Z</dc:date>
    </item>
  </channel>
</rss>

