Need Help with grep printing multiple lines.

I need help in printing multiple lines using a grep command.

The situation is like this.

I have a file that contains large number of lines

Now I need to find the the lines in the file such that if the word "AllServiceType" is found then the next line also gets printed.

Does anyone know how can I do that? The OS is AIX 6.1

Thanks.

 
awk '/AllServiceType/ {print;getline;print}' input.txt
1 Like

thanks for your response. what if there is a space in the searching word i.e. All ServiceType .. then what should be the command.

Give space

 
awk '/All ServiceType/ {print;getline;print}' input.txt

1 Like

It is not AIX specific - moving thread to other sub forum.

Thanks for the command It worked exactly the ways I wanted.

Can you please help me understand the syntax of this command. thanks.

Awk - A Tutorial and Introduction - by Bruce Barnett