The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Adding Multiple Lines to Multiple Files dayinthelife Shell Programming and Scripting 2 06-04-2008 12:50 PM
retrieved multiple lines on multiple places in a file dala Shell Programming and Scripting 8 03-14-2008 03:28 PM
copy value to multiple lines rko Shell Programming and Scripting 4 12-13-2007 10:56 PM
grep multiple lines jOOc Shell Programming and Scripting 6 11-20-2006 08:45 PM
Grep on multiple lines gundu Shell Programming and Scripting 13 03-25-2005 02:43 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-02-2005
cdunavent cdunavent is offline
Registered User
  
 

Join Date: Sep 2001
Location: D.C.
Posts: 58
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 logxx, I will get the following:

Wed Feb 2 07:44:11 <vsm> 91030 Line 5 Severity 1 Vps 6

However, what I really want are BOTH lines. Is there a way to grep and have it return both lines??

Thanks,

-cd
  #2 (permalink)  
Old 02-02-2005
thumsup9 thumsup9 is offline
Registered User
  
 

Join Date: Jan 2005
Posts: 97
Pls dont mind if this code seems stupid:

grep -i 91030 logxx >> file
grep -v 91030 logxx >> file
  #3 (permalink)  
Old 02-02-2005
cdunavent cdunavent is offline
Registered User
  
 

Join Date: Sep 2001
Location: D.C.
Posts: 58
Thanks for the attempt, but that did not do the trick.

-cd
  #4 (permalink)  
Old 02-02-2005
Neo's Avatar
Neo Neo is online now Forum Staff  
Administrator
  
 

Join Date: Sep 2000
Location: Asia Pacific
Posts: 6,799
Quote:
Originally Posted by cdunavent
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 logxx, I will get the following:

Wed Feb 2 07:44:11 <vsm> 91030 Line 5 Severity 1 Vps 6

However, what I really want are BOTH lines. Is there a way to grep and have it return both lines??

Thanks,

-cd
Please try:

grep -A1 91030 logxx

generic:

grep -A1 PATTERN [FILE...]
  #5 (permalink)  
Old 02-02-2005
cdunavent cdunavent is offline
Registered User
  
 

Join Date: Sep 2001
Location: D.C.
Posts: 58
That did not work either. Here's the error:

grep: illegal option -- A
grep: illegal option -- 1
Usage: grep -hblcnsviw pattern file . . .


Here's my box info:

ROOT@arivrc: uname -a
SunOS arivrc 5.6 Generic_105181-35 sun4u sparc SUNW,UltraSPARC-IIi-Engine
  #6 (permalink)  
Old 02-02-2005
encrypted's Avatar
encrypted encrypted is offline Forum Advisor  
Registered User
  
 

Join Date: Feb 2004
Location: Oslo, Norway
Posts: 219
Assuming that the keyword in the second line is also fixed as is the one in the first line

/usr/xpg4/bin/grep -e <keyword1> -e <keyword2> <filename>

For your file, Let's say
/usr/xpg4/bin/grep -e 91030 -e Answered logxx
  #7 (permalink)  
Old 02-02-2005
cdunavent cdunavent is offline
Registered User
  
 

Join Date: Sep 2001
Location: D.C.
Posts: 58
That did not work either. Let me see if I can be a little more specific.

Let's say I want to grep xx from logyy. I want not only the instance of xx to return, but the line directly below it as well (no matter what it is).

So basically, I am telling the shell..."find xx in my log yy. Every time you find it, show it to me, and while your at it, give me the line below it as well".

Does that make more sense??

-cd
Closed Thread

Bookmarks

Tags
linux

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:10 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0