Sample Header Ad - 728x90

Extracting paragraphs with awk

1 vote
7 answers
250 views
What is the correct way to extract paragraphs in this log file using awk: $ cat log.txt par1, line1 par1, line2 par1, line3 par1, line4 par1, line5 par1, last line par2, line1 par2, line2 par2, line3 par2, last line par3, line1 par3, line2 par3, line3 par3, line4 par3, last line Note that text as well as blank lines may have one or more spaces or tabs. Also note that blank lines could come in multiples. I tried this (which failed): awk 'BEGIN {RS="^[[:space:]]*$"} NR==2 {print "--- Paragraph",NR; print; exit}' log.txt Desired output:
--- Paragraph 2
        par2, line1
par2, line2
par2, line3
par2, last line
Asked by userene (1856 rep)
May 17, 2025, 06:12 PM
Last activity: Jul 4, 2025, 07:02 PM