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 |
Next time, try to read the related man pages, before post.
From the grep's man page: Code:
-B NUM, --before-context=NUM |
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… |
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. |
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. |
All times are GMT -5. The time now is 05:24 AM. |