[SOLVED] Grep -p for Linux, Trying to grep a paragraph.
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
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.
awk, like grep, in its default invocation, operates on
lines (records, separated by newlines), and fields (by
default separated by whitespace other than newlines).
What the awk snippet above does is to re-define records
(RS=record separator, ORS = output RS) and fields (FS=
field separator, OFS=output FS) to be the following
RS = "\n\n" = two subsequent new lines (in other words: an empty line)
FS = "\n"
So, an empty line defines a boundary between two records
(which is what you referred to as a paragraph).
Now, with the BEGIN statement awk has its behaviour
for all records and fields defined as you need them,
with NF >=4 it will print any record that has more than
4 fields (i.e., a paragraph with 4 or more lines).
@ Tinkster, My issue with the code is >4. I'm running my script on different text files that have different values. some have lines less than for and some have lines greater than 4. is there anyway I can use sed, grep or awk to capture a paragraph just like the grep -p works in AIX regardless of the size of the paragraph.
@ Tinkster, My issue with the code is >4. I'm running my script on different text files that have different values. some have lines less than for and some have lines greater than 4. is there anyway I can use sed, grep or awk to capture a paragraph just like the grep -p works in AIX regardless of the size of the paragraph.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.