Skip to content

Latest commit

 

History

History
31 lines (20 loc) · 758 Bytes

Sorting.md

File metadata and controls

31 lines (20 loc) · 758 Bytes

Sorting

Blocks of text

Single-line blocks

$ cat unsorted.txt | sed 's/^[ \t]*//' | LC_ALL=C sort -f > sorted.txt

Constants

Single-line constants with preceding single-line documentation comments

$ cat unsorted.txt | sed 's/^[ \t]*//' | awk '{getline x;print x;}1' | paste -d "\t" - - | LC_ALL=C sort -f | tr '\t' '\n' | awk '{getline x;print x;}1' > sorted.txt

Cases in switch statements

Keywords case and return on two separate single lines

$ cat unsorted.txt | sed 's/^[ \t]*//' | paste -d "\t" - - | LC_ALL=C sort -f | tr '\t' '\n' > sorted.txt

Keywords case and return on same single line

$ cat unsorted.txt | sed 's/^[ \t]*//' | LC_ALL=C sort -f > sorted.txt