Search a line and output next line as well


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Search a line and output next line as well
# 1  
Old 12-29-2008
Search a line and output next line as well

Hi,

I have a requirement to search a particular text and if found print next line also.

Appreciate your help.

Thanks
# 2  
Old 12-29-2008
Quote:
Originally Posted by kamranjalal
I have a requirement to search a particular text and if found print next line also.

Code:
text=whatever
awk '/'"$text"'/ { print; n = 1; next }
n == 1 { print; n = 0 }'

# 3  
Old 12-29-2008
Or sed:

Code:
sed -n '/text/{N;p}' file

HTH Chris
# 4  
Old 12-29-2008
Where should I put file name. Thanks again, you are awesome!
# 5  
Old 12-29-2008
I am getting following error:

sed -n '/Completed: ALTER DATABASE OPEN/{N;p}' alert_newdb.log
sed: Function /Completed: ALTER DATABASE OPEN/{N;p} cannot be parsed.

Thanks
# 6  
Old 12-29-2008
Quote:
Originally Posted by kamranjalal
Hi,

I have a requirement to search a particular text and if found print next line also.

Appreciate your help.

Thanks
(Asumming this is Linux)
Another though would be:
grep -b1 -a1 java /var/log/someserver.log

-b1 one line before "java"
-a1 one line following "java"
# 7  
Old 12-29-2008
Sorry my mistake it is :
HP-UX B.11.11

My bad forgot to tell OS
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Search a multi-line shell command output and execute logic based on result

The following is a multi-line shell command example: $cargo build Compiling prawn v0.1.0 (/Users/ag/rust/prawn) error: failed to resolve: could not find `setup_panix` in `human_panic` --> src/main.rs:14:22 | 14 | human_panic::setup_panix!(); | ... (2 Replies)
Discussion started by: yogi
2 Replies

2. UNIX for Beginners Questions & Answers

Get an output of lines in pattern 1st line then 10th line then 11th line then 20th line and so on.

Input file: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 (6 Replies)
Discussion started by: Sagar Singh
6 Replies

3. Shell Programming and Scripting

(n)awk: print regex search output lines in one line

Hello. I have been looking high and low for the solution for this. I seems there should be a simple answer, but alas. I have a big xml file, and I need to extract certain information from specific items. The information I need can be found between a specific set of tags. let's call them... (2 Replies)
Discussion started by: Tobias-Reiper
2 Replies

4. Shell Programming and Scripting

Multiple line search, replace second line, using awk or sed

All, I appreciate any help you can offer here as this is well beyond my grasp of awk/sed... I have an input file similar to: &LOG &LOG Part: "@DB/TC10000021855/--F" &LOG &LOG &LOG Part: "@DB/TC10000021852/--F" &LOG Cloning_Action: RETAIN &LOG Part: "@DB/TCCP000010713/--A" &LOG &LOG... (5 Replies)
Discussion started by: KarmaPoliceT2
5 Replies

5. Shell Programming and Scripting

String search and print next all lines in one line until blank line

Dear all I want to search special string in file and then print next all line in one line until blank lines come. Help me plz for same. My input file and desire op file is as under. i/p file: A1/EXT "BSCABD1_21233G1" 757 130823 1157 RADIO X-CEIVER ADMINISTRATION BTS EXTERNAL FAULT ... (7 Replies)
Discussion started by: jaydeep_sadaria
7 Replies

6. Shell Programming and Scripting

PERL or SHELL Scrript to search in Directories by taking line by line from a text file

Unix box server version *********** >uname -r B.11.00 >echo $SHELL /usr/bin/ksh --> in this server, I have the path like /IMbuild/dev/im0serv1 ---> in that directory I have the folders startup(.jsp files nearly 100 jsp's ) and scripts(contains .js files nearly 100 files) ... (9 Replies)
Discussion started by: pasam
9 Replies

7. Shell Programming and Scripting

search a string in a particular column of file and return the line number of the line

Hi All, Can you please guide me to search a string in a particular column of file and return the line number of the line where it was found using awk. As an example : abc.txt 7000,john,2,1,0,1,6 7001,elen,2,2,0,1,7 7002,sami,2,3,0,1,6 7003,mike,1,4,0,2,1 8001,nike,1,5,0,1,8... (3 Replies)
Discussion started by: arunshankar.c
3 Replies

8. Shell Programming and Scripting

perl search and replace - search in first line and replance in 2nd line

Dear All, i want to search particular string and want to replance next line value. following is the test file. search string is tmp,??? ,10:1 "???" may contain any 3 character it should remain the same and next line replace with ,10:50 tmp,123 --- if match tmp,??? then... (3 Replies)
Discussion started by: arvindng
3 Replies

9. Shell Programming and Scripting

search and goto next line then take the output

Hi All, I have a file in which the contents are as shown below: Number of Dynamic Addresses Allocated : 107790 Addresses: 10.3.29.202,10.47.1.145,10.2.4.98,190.1.89.95,.. (many ip addresses separated by comma) ----... (3 Replies)
Discussion started by: imas
3 Replies

10. UNIX for Dummies Questions & Answers

query on how to search for a line and read 4th word from that line

Assume I have a text file as below: me con pi ind ken pras ur me con rome ind kent pras urs pintu con mys ind pan pras ki con kit ind sys My requirement, I need to search for "con rome" and if exists, then print 4th word from rome, i.e in above example, since "con rome"... (4 Replies)
Discussion started by: jaggesh
4 Replies
Login or Register to Ask a Question