aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/tools/sort.md
diff options
context:
space:
mode:
authorJohannes Stoelp <johannes.stoelp@gmail.com>2024-01-17 23:45:30 +0100
committerJohannes Stoelp <johannes.stoelp@gmail.com>2024-01-17 23:45:30 +0100
commit1d5addd14bc3f0c7279b41882fc9b8ff60fac450 (patch)
tree376526127f3b0e01cd435e2f51fb152470dcf65d /src/tools/sort.md
parent6ab4d0859f32d96af2b39a95d943ffeab0d4d713 (diff)
downloadnotes-1d5addd14bc3f0c7279b41882fc9b8ff60fac450.tar.gz
notes-1d5addd14bc3f0c7279b41882fc9b8ff60fac450.zip
sort: add initial examples
Diffstat (limited to 'src/tools/sort.md')
-rw-r--r--src/tools/sort.md35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/tools/sort.md b/src/tools/sort.md
new file mode 100644
index 0000000..e74b490
--- /dev/null
+++ b/src/tools/sort.md
@@ -0,0 +1,35 @@
+# sort(1)
+
+```
+sort [opts] [file]
+ opts:
+ -r reverse output
+ -b ignore leading blanks
+
+ -n sort by numeric
+ -h sort by human numeric
+ -V sort by version
+
+ -k<N> sort by Nth key
+ -t<S> field separator
+```
+
+## Examples
+```sh
+# Sort by directory sizes.
+du -sh * | sort -h
+```
+
+```sh
+# Sort numeric by second key.
+# The default key separator is non-blank to blank transition.
+echo 'a 4
+d 10
+c 21' | sort -k2 -n
+
+# Sort numeric by second key, split at comma.
+echo 'a,4
+d,10
+c,21' | sort -k2 -n -t,
+```
+> Use `--debug` to annotate part of the line used to sort and hence debug the key usage.