Need Help with grep printing multiple lines.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need Help with grep printing multiple lines.
# 1  
Old 04-19-2012
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.
# 2  
Old 04-19-2012
Code:
 
awk '/AllServiceType/ {print;getline;print}' input.txt

This User Gave Thanks to itkamaraj For This Post:
# 3  
Old 04-19-2012
thanks for your response. what if there is a space in the searching word i.e. All ServiceType .. then what should be the command.
# 4  
Old 04-19-2012
Give space

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

This User Gave Thanks to itkamaraj For This Post:
# 5  
Old 04-19-2012
It is not AIX specific - moving thread to other sub forum.
# 6  
Old 04-23-2012
Thanks for the command It worked exactly the ways I wanted.


Can you please help me understand the syntax of this command. thanks.
# 7  
Old 04-23-2012
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Printing multiple lines on the same line between specific text

This is an extract from a large file. The lines that start with fc are ports on a fabric switch. In between each fc port there is information about the port. fc2/12 is up Port description is SEIEDISCOVER-3 Speed is 4 Gbps fc2/13 is down (Administratively down) fc2/14 is up Port... (1 Reply)
Discussion started by: kieranfoley
1 Replies

2. Shell Programming and Scripting

Trouble printing multiple lines to a new file

Hi, I'm trying to auto generate some php files with a default preamble at the top which is a block comment. The problem is that my output has no new lines and it looks like the output from "ls" is being printed after everyline This is my code #!/bin/bash read -d '' pre_amble... (1 Reply)
Discussion started by: racshot65
1 Replies

3. UNIX for Advanced & Expert Users

grep across multiple lines

How do you grep 'select * from table_name' string from a script if the select * and from table_name are on 2 different lines ? like select * from table_name Any help would be greatly appreciated !!! Thanks RDR (4 Replies)
Discussion started by: RDR
4 Replies

4. UNIX for Dummies Questions & Answers

grep in multiple lines

hi i have kind of below text in a file. I want to get a complete paragraph starting with START and ending with before another START) which has a particular string say XYZ or ABC START XYZ hshjghkjh 45 ljkfd fldjlj d jldf START 3493u ABC 454 4545454 4545454 45454 4545454 START ...... (3 Replies)
Discussion started by: reldb
3 Replies

5. UNIX for Dummies Questions & Answers

grep command to find multiple strings in multiple lines in a file.

I want to search files (basically .cc files) in /xx folder and subfolders. Those files (*.cc files) must contain #include "header.h" AND x() function. I am writing it another way to make it clear, I wanna list of *.cc files that have 'header.h' & 'x()'. They must have two strings, header.h... (2 Replies)
Discussion started by: ritikaSharma
2 Replies

6. Shell Programming and Scripting

Help required on grep command(Skip the first few lines from printing in the output)

Hi experts I want the proper argument to the grep command so that I need to skip the first few lines(say first 10 lines) and print all the remaining instances of the grep output. I tried to use grep -m 10 "search text" file*. But this gives the first 10 instances(lines) of the search string.... (7 Replies)
Discussion started by: ks_reddy
7 Replies

7. Shell Programming and Scripting

Perl: Printing Multiple Lines after pattern match

Hello People, Need some assistance/guidance. OUTLINE: Two files (File1 and File2) File1 has some ids such as 009463_3922_1827 897654_8764_5432 File2 has things along the lines of: Query= 009463_3922_1827 length=252 (252 letters) More stufff here ... (5 Replies)
Discussion started by: Deep9000
5 Replies

8. Shell Programming and Scripting

Printing out multiple lines with a correct format

Hello, This is my first post and I've just started on UNIX in school. A file name "list" has the following content (excluding the numbers and the bottom part): 1 2 3 4 5 6 0123456789012345678901234567890123456789012345678901234567890 IT ... (1 Reply)
Discussion started by: cooolway
1 Replies

9. Shell Programming and Scripting

grep multiple lines

Hey guys: I've been meaning to post this question for awhile...it is regarding grep. Let's say for example that the following entry is in logxx: Wed Feb 2 07:44:11 <vsm> 91030 Line 5 Severity 1 Vps 6 Call Answered - DN:8753101 CLID:5164665761 PI:83 If I do a grep 91030... (27 Replies)
Discussion started by: cdunavent
27 Replies

10. Shell Programming and Scripting

Grep on multiple lines

I 'm trying to grep 2 fieldds on 2 differnt lines. Like this: psit > file egrep -e '(NS|ES)' $file. Not working. If this succeeds then run next cmd else exit. Pls Help Gundu (13 Replies)
Discussion started by: gundu
13 Replies
Login or Register to Ask a Question