up vote 1 down vote favorite
share [fb]

How can I grep a paragraph from a file in the Solaris operating system? I tried the -p option used in AIX, but it's not useful in Solaris.

grep -p Accept is not working in Solaris. Is there any other option?

link|improve this question
For future reference, I probably would have asked this on Super User. Don't go and ask it there now though. If others agree with me, it will be migrated there automagically :) – Cam Jackson Sep 14 at 5:17
I didn't understand:-( – Raje Sep 14 at 6:12
That's ok! You're not the first, and you certainly won't be the last! Besides, someone with over 100k rep thought your question was relevant to answer, and there haven't been enough people voting with me to move your question to superuser, so maybe I was wrong anyway. Shell commands/scripting is a bit of a grey area. – Cam Jackson Sep 14 at 6:19
Have you checked /opt/swf/bin for a GNU grep? It is probably not in the PATH. – ceving Sep 14 at 19:59
feedback

migrated from stackoverflow.com Sep 14 at 11:27

This question came from our site for professional and enthusiast programmers.

2 Answers

Awk is present on every unix (it's standard). Anything that grep or sed can do, can be coded in awk (but it's not always straightforward).

Awk operates record by record. The default record separator is a newline (i.e. by default, a record is a line), but if the RS variable is set to an empty value, then the record separator is one or more empty lines (i.e. a record is a paragraph).

awk -v RS= '/needle/'
link|improve this answer
feedback

Using the standard grep, there isn't a sensible alternative. You can either install a more capable version of grep (perhaps GNU grep), or you can use Perl (or perhaps Python) to emulate grep.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown