LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-20-2005, 08:52 AM   #1
sanjith11
Member
 
Registered: Oct 2003
Distribution: redhat
Posts: 63

Rep: Reputation: 15
help on grep!!!!


hi all,

How can i grep a pattern and obtain the adjecent lines aswell of the matching pattern?

also can i get the line number of the matching line using grep.


regards
SaN
 
Old 01-20-2005, 08:56 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
did you check the grep manpage? http://www.hmug.org/man/1/grep.html you want -A 1 and -B 1. simple....
 
Old 01-20-2005, 09:02 AM   #3
sanjith11
Member
 
Registered: Oct 2003
Distribution: redhat
Posts: 63

Original Poster
Rep: Reputation: 15
thanks for that!!!!!


next time i will do that before posting any thing over here!!!!

thanks agen!!!
 
Old 01-20-2005, 09:10 AM   #4
sanjith11
Member
 
Registered: Oct 2003
Distribution: redhat
Posts: 63

Original Poster
Rep: Reputation: 15
Unhappy not working in HP-UX

Is there any suggestions for the same problem on HP-UX.
grep in HP-UX dosent have options like 'A' or 'B'...tried in the man page but it says nothin about the line number or the way to get the adjacent lines printed!!!!!!!!
 
Old 01-20-2005, 02:16 PM   #5
slackie1000
Senior Member
 
Registered: Dec 2003
Location: Brasil
Distribution: Arch
Posts: 1,037

Rep: Reputation: 46
hi there,

afaik nope. you could try the parameter '-n'. getting the line number that matches you could write a script with head + tail to get the adjacents lines. i believe should exist a better solution for that. hope some guru can give you the answer.

regards

slackie1000
 
Old 01-20-2005, 05:43 PM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Ask your sysadmin team if the GNU tools are installed, usually under /opt, but could be anywhere.
Then ensure that path is added to your PATH env variable.
The flags you're looking for are GNU extensions.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
grep ?? can grep us variables? DaFrEQ Linux - Software 4 09-14-2005 12:22 PM
What does rpm -qa |grep th* (as compared to rpm -qa |grep th) display? davidas Linux - Newbie 2 03-18-2004 01:35 AM
"Undeleting" data using grep, but get "grep: memory exhausted" error SammyK Linux - Software 2 03-13-2004 03:11 PM
ps -ef|grep -v root|grep apache<<result maelstrombob Linux - Newbie 1 09-24-2003 11:38 AM
Grep and '-' Wynd Linux - General 5 06-13-2003 05:14 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:31 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration