The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Perl: Search for string on line then search and replace text Crypto Shell Programming and Scripting 4 01-04-2008 07:24 AM
Multiple file processing - 1st line only to process - search/match substring toneatlondon Shell Programming and Scripting 2 01-02-2008 06:20 PM
Search first line of compressed file cbreiner UNIX for Advanced & Expert Users 1 09-05-2007 02:52 PM
search and retrieve previous line in file paulsew Shell Programming and Scripting 2 02-23-2007 05:04 AM
In Line File Modifications: Search and Replace Shakey21 Shell Programming and Scripting 2 11-20-2001 01:21 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 07-02-2007
Registered User
 

Join Date: Jul 2007
Posts: 2
Search in a file and get the next line as well

Hi All,
i'm new here in the forum and UNIX too.
I have a quick question.
I have a file containing the following lines:


3:40:27 su :0002:9999:2:399
[ID 366847 auth.info] 'su sdfrun' succeeded for root on /dev/???

23:40:29 su :0005:0342:2:1
Disk Utilization threshold



What i want to do is search for a parameter on the first line e.g. 0005 and have as result time and second line printed as well.
This is my expected printout if I search for 0005

23:40:29 su :0005:0342:2:1 Disk Utilization threshold

So far i did this, but it doesn't help


"#!/bin/ksh


for enum in "0005 0060 0055"

do

while IFS= read -r line

do

echo "grep $enum /home/salvatore/alarms/$IFS"

done < input_file

This gives me just the first line

Thanks a lot
Reply With Quote
Forum Sponsor
  #2  
Old 07-02-2007
Shell_Life's Avatar
Registered User
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
Code:
sed -n '/0005/{N;p;}' input_file
Reply With Quote
  #3  
Old 07-02-2007
Registered User
 

Join Date: Jul 2007
Posts: 2
Thanks a lot
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 01:48 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0