Solaris / OpenSolaris This forum is for the discussion of Solaris and OpenSolaris.
General Sun, SunOS and Sparc related questions also go here. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
12-21-2007, 09:44 AM
|
#1
|
|
LQ Newbie
Registered: Jul 2006
Posts: 14
Rep:
|
SED question
Hello.
I have a SED question. If the following command prints out "patterntomatch" as well as the next 3 lines from a file, how can it be written to grep out the string and the 3 lines above it?
sed -ne "/patterntomatch/{p;n;p;n;p;}" filename
|
|
|
|
12-21-2007, 09:56 AM
|
#2
|
|
Senior Member
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,392
Rep:
|
Next time, try to read the related man pages, before post.
From the grep's man page:
Code:
-B NUM, --before-context=NUM
Print NUM lines of leading context before matching lines.
Places a line containing -- between contiguous groups of
matches.
|
|
|
|
12-21-2007, 12:59 PM
|
#3
|
|
LQ Newbie
Registered: Jul 2006
Posts: 14
Original Poster
Rep:
|
Actually, I did read through the man pages, as I always do before posting.
I am new to the sed command and did see that in the man pages but did not interpret it this way. I am still not sure how to convert my command above to do what I need it to using the –B NUM argument…
|
|
|
|
12-21-2007, 02:04 PM
|
#4
|
|
Moderator
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Ubuntu, OL
Posts: 9,311
|
Just a side comment. This "-B" option is a Gnu extension so isn't supported by Solaris grep nor the standard compliant /usr/xpg4/bin/grep.
It is available under the "ggrep" name under Solaris.
|
|
|
|
12-26-2007, 04:29 AM
|
#5
|
|
Senior Member
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,392
Rep:
|
Thanks jlliagre for pointing the right command in solaris.
Hi qipman, take a look on -A, -B and -C flags of ggrep. They will print lines n lines around the line it find a match (after, before and around). So you can use something like "ggrep -A 3 patterntomatch filename" to print the line that have a match and the next 3 lines.
|
|
|
|
| Thread Tools |
Search 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
HTML code is Off
|
|
|
All times are GMT -5. The time now is 08:38 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|