Match something then process next line 
Author Message
 Match something then process next line

Hi All

Pretty simple one I think:  

I need a little awk script to match (regex) something in a file then
process the next line in the file (e.g.   like print the first 2
fields in the next line).  I have read a lot of docs but have not
found the right solution.

Thanks...

Dave



Sun, 23 May 2004 05:39:10 GMT  
 Match something then process next line

Quote:

>Hi All

>Pretty simple one I think:

>I need a little awk script to match (regex) something in a file then
>process the next line in the file (e.g.   like print the first 2
>fields in the next line).  I have read a lot of docs but have not
>found the right solution.

/regex/{getline;print $1, $2}

/regex/{found_it=1;next}
found_it==1{print $1,$2;found_it=0}

/regex/{its_here=NR}
NR==(its_here+1){print $1,$2}



Sun, 23 May 2004 07:39:46 GMT  
 Match something then process next line


Quote:
>Hi All

>Pretty simple one I think:  

>I need a little awk script to match (regex) something in a file then
>process the next line in the file (e.g.   like print the first 2
>fields in the next line).  I have read a lot of docs but have not
>found the right solution.

i started trying gawk last night...my first attempt seems to match
what you want. it looks for a line containing 'six'  and then prints
the next few lines:

/six/ {count = 1}

{if (count > 0 && count < 4)
    {print $0, count;  count++}}

no doubt somebody will tell me i've got it all wrong, but it worked
for me :)

actually, i'm trying to write something that will find a string and
then output n lines before and n lines after the line containing that
string...like search/window=(100,100) in VMS.

i assume i've got to close and re-open the file once i've found the
line? or can i go backwards through it?

jack
tomorrow's almost over, today went by so fast...



Thu, 27 May 2004 16:29:01 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Search file and print line + next line?

2. awk -- pattern match a line and the line that follows

3. Next(Entity) Is There SomeThing FASTER???

4. How do you match something that is not the specified pattern inEx

5. How do you match something that is not the specified pattern in

6. How do you match something that is not the specified pattern in E

7. How do you match something that is not the specified pattern in Expec

8. How to process something on a special time event

9. processes sharing something

10. next(process:view)

11. Case-insensitive pattern matching for HTML processing

12. processing matched patterns in sit-u

 

 
Powered by phpBB® Forum Software