Unix Technical Forum

Re: Return second line after a pattern match?

This is a discussion on Re: Return second line after a pattern match? within the AIX Operating System forums, part of the Unix Operating Systems category; --> Ritchie wrote: > > I'm stuck trying to figure this out. Say I have a file with the > ...


Go Back   Unix Technical Forum > Unix Operating Systems > AIX Operating System

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-04-2008, 06:59 PM
scriptOmatic
 
Posts: n/a
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


--
http://ftp.opensysmon.com is a shell script archive site with an
open source system monitoring and network monitoring software package.
Many platforms are supplied already compiled.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 01-04-2008, 06:59 PM
Alain Deschamps
 
Posts: n/a
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



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 07:49 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com