<?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 output in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/script-output/m-p/3101501#M146980</link>
    <description>A much similar problem was recently asked and answered in:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=237288" target="_blank"&gt;http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=237288&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;My reply there adapted (but untested) for your problem: &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;awk '/&lt;STRING&gt;/{i=&lt;LINES&gt;; while (i--) {getline; print $0}}' &amp;lt; &lt;FILE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;or PERL (assuring a re-start every occurence:&lt;BR /&gt;&lt;BR /&gt;cat &lt;FILE&gt; | perl -e 'while (&amp;lt;&amp;gt;){print if ($i--&amp;gt;0); $i=&lt;LINES&gt; if (/&lt;STRING&gt;/)}'&lt;/STRING&gt;&lt;/LINES&gt;&lt;/FILE&gt;&lt;/FILE&gt;&lt;/LINES&gt;&lt;/STRING&gt;</description>
    <pubDate>Sat, 25 Oct 2003 16:16:05 GMT</pubDate>
    <dc:creator>Hein van den Heuvel</dc:creator>
    <dc:date>2003-10-25T16:16:05Z</dc:date>
    <item>
      <title>script output</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-output/m-p/3101498#M146977</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;Ive been having this problem doing a script that when it encounters xxx in a particular line it prints n number of line below it. Hope you can help me thanks.&lt;BR /&gt;&lt;BR /&gt;Example cat myfile  &lt;BR /&gt;xxx&lt;BR /&gt;asdfghjkl&lt;BR /&gt;aaa&lt;BR /&gt;poiuyuiyequye&lt;BR /&gt;bbb&lt;BR /&gt;opfdpop[o[pop[o&lt;BR /&gt;xxx&lt;BR /&gt;qwerty&lt;BR /&gt;poiu&lt;BR /&gt;pdiofgshf&lt;BR /&gt;&lt;BR /&gt;produce output when n=1 (1 line below it)&lt;BR /&gt;&lt;BR /&gt;asdfghjkl&lt;BR /&gt;qwerty&lt;BR /&gt;&lt;BR /&gt;produce output when n=2 (print 2 lines below it)&lt;BR /&gt;&lt;BR /&gt;asdfghjkl&lt;BR /&gt;aaa&lt;BR /&gt;qwerty&lt;BR /&gt;poiu&lt;BR /&gt;</description>
      <pubDate>Fri, 24 Oct 2003 05:52:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-output/m-p/3101498#M146977</guid>
      <dc:creator>Ferdie Castro</dc:creator>
      <dc:date>2003-10-24T05:52:48Z</dc:date>
    </item>
    <item>
      <title>Re: script output</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-output/m-p/3101499#M146978</link>
      <description>You could use awk, and pass in the number of lines to print, as follows.&lt;BR /&gt;&lt;BR /&gt;awk -v lines=1 '&lt;BR /&gt;/xxx/ {&lt;BR /&gt;      for (i=1;i&amp;lt;=lines;i++) {&lt;BR /&gt;       getline&lt;BR /&gt;       print&lt;BR /&gt;    }&lt;BR /&gt;} ' myfile&lt;BR /&gt;--&lt;BR /&gt;Use lines=1, lines=2, or whatever.&lt;BR /&gt;/xxx will match "xxx" anywhere on the line, if you only want beginning of line, use /^xxx/&lt;BR /&gt;--&lt;BR /&gt;Graham</description>
      <pubDate>Fri, 24 Oct 2003 06:03:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-output/m-p/3101499#M146978</guid>
      <dc:creator>Graham Cameron_1</dc:creator>
      <dc:date>2003-10-24T06:03:24Z</dc:date>
    </item>
    <item>
      <title>Re: script output</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-output/m-p/3101500#M146979</link>
      <description>Ferdie,&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/ksh&lt;BR /&gt;# Filename: script.sh&lt;BR /&gt;&lt;BR /&gt;awk -v string=$1 -v lines=$2 '{&lt;BR /&gt;tmplines=lines;&lt;BR /&gt;if ($0 ~ string)&lt;BR /&gt;{&lt;BR /&gt;while (tmplines-- &amp;gt; 0)&lt;BR /&gt;{&lt;BR /&gt;getline;&lt;BR /&gt;print $0;&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}' /tmp/a.txt&lt;BR /&gt;&lt;BR /&gt;# where /tmp/a.txt is your text file with the strings.&lt;BR /&gt;# eof&lt;BR /&gt;&lt;BR /&gt;Call this as follows -&lt;BR /&gt;# script.sh "xxx" 1&lt;BR /&gt;asdfghjkl&lt;BR /&gt;qwerty&lt;BR /&gt;# script.sh "xxx" 2&lt;BR /&gt;asdfghjkl&lt;BR /&gt;aaa&lt;BR /&gt;qwerty&lt;BR /&gt;poiu&lt;BR /&gt;&lt;BR /&gt;HTH.&lt;BR /&gt;- ramd.</description>
      <pubDate>Fri, 24 Oct 2003 06:09:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-output/m-p/3101500#M146979</guid>
      <dc:creator>Ramkumar Devanathan</dc:creator>
      <dc:date>2003-10-24T06:09:54Z</dc:date>
    </item>
    <item>
      <title>Re: script output</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-output/m-p/3101501#M146980</link>
      <description>A much similar problem was recently asked and answered in:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=237288" target="_blank"&gt;http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=237288&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;My reply there adapted (but untested) for your problem: &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;awk '/&lt;STRING&gt;/{i=&lt;LINES&gt;; while (i--) {getline; print $0}}' &amp;lt; &lt;FILE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;or PERL (assuring a re-start every occurence:&lt;BR /&gt;&lt;BR /&gt;cat &lt;FILE&gt; | perl -e 'while (&amp;lt;&amp;gt;){print if ($i--&amp;gt;0); $i=&lt;LINES&gt; if (/&lt;STRING&gt;/)}'&lt;/STRING&gt;&lt;/LINES&gt;&lt;/FILE&gt;&lt;/FILE&gt;&lt;/LINES&gt;&lt;/STRING&gt;</description>
      <pubDate>Sat, 25 Oct 2003 16:16:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-output/m-p/3101501#M146980</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2003-10-25T16:16:05Z</dc:date>
    </item>
  </channel>
</rss>

