Return second line after a pattern match?

Ask a Question related to AIX, Design and Development.

  1. #1

    Default Re: Return second line after a pattern match?

    Ritchie wrote:
    >
    > I'm stuck trying to figure this out. Say I have a file with the
    > results of a command (lets say: svmon -Put 10) which shows the top 10
    > usage processes. Each of the returned 10 records in the file is
    > separated by dashes "-----------". How would you guys code a command
    > which returns the 2nd line after you encounter and match the line of
    > dashes? Matching the dashes isn't difficult but I can't figure out
    > how to get the 2nd line after each match.
    >
    > Thanks - Ritchie
    is this what you want?
    find the "----------" line and skip it
    fine the 1st line after it and skip it
    find the 2nd line after it and print it
    skip all other lines



    use nawk

    BEGIN { cnt = 0 ; }

    /.*----------.*/ { cnt = 1; next; }
    cnt == 1 { cnt ++; next; }
    cnt == 2 { print; cnt ++; } # print 2nd line past "----"
    # ignore all other lines


    --
    [url]http://ftp.opensysmon.com[/url] is a shell script archive site with an
    open source system monitoring and network monitoring software package.
    Many platforms are supplied already compiled.
    scriptOmatic Guest

  2. Similar Questions and Discussions

    1. Use of uninitialized value in pattern match (m//) at ./getopt.pl line 14.
      Hi, I'm trying to be a good boy and use strict and warnings .. The more I do, the more I feel I'm wasting so much time and should become...
    2. pattern match
      Where can I find infi or doc on "pattern match" used within WHERE clause (mysql). As I need to matche with PHP variables I'd prfer something...
    3. please help !! pattern match
      Hi , I need some help me to extract a pattern. The delimiters is a pair of "abcd" and "efgh". Can some one help me with an efficient use of Greedy...
    4. uninitialized value in pattern match
      #!/usr/bin/perl use warnings; use strict "refs"; use strict "subs"; use strict "vars"; our $netscape; $netscape = ($ENV{HTTP_USER_AGENT}...
    5. Pattern match with 2 conditions
      Stephan Bour <sbour@niaid.nih.gov> writes: use strict; # is your friend what's the point of this when you just set it back to "" below? ...
  3. #2

    Default Re: Return second line after a pattern match?

    On Tue, 29 Jul 2003 19:33:06 GMT, scriptOmatic
    <ScriptOmatic@ChironComputing.Com> wrote:
    >Ritchie wrote:
    >>
    >> I'm stuck trying to figure this out. Say I have a file with the
    >> results of a command (lets say: svmon -Put 10) which shows the top 10
    >> usage processes. Each of the returned 10 records in the file is
    >> separated by dashes "-----------". How would you guys code a command
    >> which returns the 2nd line after you encounter and match the line of
    >> dashes? Matching the dashes isn't difficult but I can't figure out
    >> how to get the 2nd line after each match.
    >>
    >> Thanks - Ritchie
    >
    >is this what you want?
    >find the "----------" line and skip it
    >fine the 1st line after it and skip it
    >find the 2nd line after it and print it
    >skip all other lines
    >
    >
    >
    >use nawk
    >
    >BEGIN { cnt = 0 ; }
    >
    >/.*----------.*/ { cnt = 1; next; }
    >cnt == 1 { cnt ++; next; }
    >cnt == 2 { print; cnt ++; } # print 2nd line past "----"
    ># ignore all other lines
    To get *every* 2nd lines after each dashes lines you can use :

    awk '/.*----------.*/ { getline; getline, print }'

    AD



    Alain Deschamps Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139