LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   help on grep!!!! (https://www.linuxquestions.org/questions/programming-9/help-on-grep-280095/)

sanjith11 01-20-2005 08:52 AM

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

acid_kewpie 01-20-2005 08:56 AM

did you check the grep manpage? http://www.hmug.org/man/1/grep.html you want -A 1 and -B 1. simple....

sanjith11 01-20-2005 09:02 AM

thanks for that!!!!!


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

thanks agen!!!

sanjith11 01-20-2005 09:10 AM

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!!!!!!!!

slackie1000 01-20-2005 02:16 PM

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

chrism01 01-20-2005 05:43 PM

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.


All times are GMT -5. The time now is 06:32 PM.