mirror of
https://gitea.com/mcereda/oam.git
synced 2026-02-23 03:54:28 +00:00
chore: integrated notions from articles on bash
This commit is contained in:
@@ -1,23 +1,35 @@
|
||||
# Sort
|
||||
|
||||
## Table of contents <!-- omit in toc -->
|
||||
|
||||
1. [TL;DR](#tldr)
|
||||
1. [Sort by the value in the last field](#sort-by-the-value-in-the-last-field)
|
||||
1. [Sources](#sources)
|
||||
|
||||
## TL;DR
|
||||
|
||||
```sh
|
||||
# Sort given lines.
|
||||
sort path/to/file
|
||||
sort 'path/to/file'
|
||||
|
||||
# Sort lines in reverse.
|
||||
sort -r path/to/file
|
||||
sort -r 'path/to/file'
|
||||
|
||||
# Sort lines numerically.
|
||||
sort -n path/to/file
|
||||
sort -n 'path/to/file'
|
||||
|
||||
# Sort lines and remove duplicates.
|
||||
sort -u path/to/file
|
||||
sort -u 'path/to/file'
|
||||
|
||||
# Sort lines in random order.
|
||||
sort -R 'path/to/file'
|
||||
|
||||
# Sort lines numerically according to the value in the 3rd column.
|
||||
sort -t $'\t' -k 3n,3 'path/to/file'
|
||||
|
||||
# Sort by the value in the last field.
|
||||
awk 'BEGIN {FS=","; OFS="|"} {print $NF,$0}' file.txt \
|
||||
| sort -n -t '|' | awk -F '|' '{print $NF}'
|
||||
| sort -n -t '|' | awk -F '|' '{print $NF}'
|
||||
```
|
||||
|
||||
## Sort by the value in the last field
|
||||
@@ -45,5 +57,11 @@ awk 'BEGIN {FS=","; OFS="|"} {print $NF,$0}' file.txt \
|
||||
## Sources
|
||||
|
||||
- [Sort a file in Unix based on the last field]
|
||||
- [The essential Bash cheat sheet]
|
||||
|
||||
<!-- project's references -->
|
||||
<!-- in-article references -->
|
||||
<!-- internal references -->
|
||||
<!-- external references -->
|
||||
[sort a file in unix based on the last field]: http://www.unixcl.com/2010/11/sort-file-based-on-last-field-unix.html
|
||||
[the essential bash cheat sheet]: https://betterprogramming.pub/the-essential-bash-cheat-sheet-e1c3df06560
|
||||
|
||||
Reference in New Issue
Block a user