'Sorting paragraphs in bash (awk or sed)?
To sort various paragraphs (abc order) I tried:
awk 'BEGIN { RS="" } { a[FNR]=$0 } END { PROCINFO["sorted_in"]="@val_str_asc" for (i in a) print a[i] ORS } ' myrecords.txt
But it won't sort. Sample records:
Ham
this is good
(mind the mail)
Cheese
I'm fine
Turkey
(empty)
Blocks of text might got one or more lines, seperated by one or more blank lines or even a date instead of a blank. The latter can be solved by replacing the date with a blank line.
Desired result:
Cheese
I'm fine
Ham
this is good
(mind the mail)
Turkey
(empty)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
