Solaris / OpenSolarisThis forum is for the discussion of Solaris, OpenSolaris, OpenIndiana, and illumos.
General Sun, SunOS and Sparc related questions also go here. Any Solaris fork or distribution is welcome.
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.
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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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.
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…
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.