This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | Previous revision | ||
os:filters [2019/11/18 22:10] |
os:filters [2021/11/09 07:43] (current) zioskenz |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Filters ====== | ||
+ | Return to [[os: | ||
+ | Examples about filters, i.e., commands '' | ||
+ | |||
+ | |||
+ | ===== Example files ===== | ||
+ | |||
+ | <code txt example.txt> | ||
+ | 408 Rossi Giulia 30.0 | ||
+ | 12 Rossi Stefania 21.5 | ||
+ | 234 Bianchi Gianna 17.0 | ||
+ | 123 Bianchi Bianchi 30.0 | ||
+ | </ | ||
+ | |||
+ | <code txt example_uniq.txt> | ||
+ | Gabriele | ||
+ | Giulia | ||
+ | Stefano | ||
+ | Stefano | ||
+ | Stefano S | ||
+ | Stefania | ||
+ | </ | ||
+ | |||
+ | |||
+ | ===== '' | ||
+ | |||
+ | <code bash> | ||
+ | > cut -d ' ' -f 1,4 example.txt | ||
+ | 12 21.5 | ||
+ | 408 30.0 | ||
+ | 234 17.0 | ||
+ | 123 30.0 | ||
+ | </ | ||
+ | |||
+ | <code bash> | ||
+ | > cut -d ' ' -f 1-2,4 example.txt | ||
+ | 12 Rossi 21.5 | ||
+ | 408 Rossi 30.0 | ||
+ | 234 Bianchi 17.0 | ||
+ | 123 Bianchi 30.0 | ||
+ | </ | ||
+ | |||
+ | ===== '' | ||
+ | |||
+ | <code bash> | ||
+ | > tr -s sn < example.txt | ||
+ | 408 Rosi Giulia 30.0 | ||
+ | 12 Rosi Stefania 21.5 | ||
+ | 234 Bianchi Giana 17.0 | ||
+ | 123 Bianchi Bianchi 30.0 | ||
+ | </ | ||
+ | |||
+ | <code bash> | ||
+ | > tr -d si < example.txt | ||
+ | 408 Ro Gula 30.0 | ||
+ | 12 Ro Stefana 21.5 | ||
+ | 234 Banch Ganna 17.0 | ||
+ | 123 Banch Banch 30.0 | ||
+ | </ | ||
+ | |||
+ | * Replace everything that is **not** the letter '' | ||
+ | <code bash> | ||
+ | > echo "hello world" | tr -c l X | ||
+ | XXllXXXXXlXX | ||
+ | </ | ||
+ | |||
+ | * Replace everything that is **not** a digit with the character '' | ||
+ | <code bash> | ||
+ | > echo " | ||
+ | --------123--------345- | ||
+ | </ | ||
+ | |||
+ | ===== '' | ||
+ | |||
+ | <code bash> | ||
+ | > uniq example_uniq.txt | ||
+ | Gabriele | ||
+ | Giulia | ||
+ | Stefano | ||
+ | Stefano S | ||
+ | Stefania | ||
+ | </ | ||
+ | |||
+ | <code bash> | ||
+ | > uniq -c example_uniq.txt | ||
+ | 1 Gabriele | ||
+ | 1 Giulia | ||
+ | 2 Stefano | ||
+ | 1 Stefano S | ||
+ | 1 Stefania | ||
+ | </ | ||
+ | |||
+ | <code bash> | ||
+ | > uniq -d example_uniq.txt | ||
+ | Stefano | ||
+ | </ | ||
+ | |||
+ | ===== '' | ||
+ | |||
+ | <code bash> | ||
+ | > sort -k1,1n example.txt | ||
+ | 12 Rossi Stefania 21.5 | ||
+ | 123 Bianchi Bianchi 30.0 | ||
+ | 234 Bianchi Gianna 17.0 | ||
+ | 408 Rossi Giulia 30.0 | ||
+ | </ | ||
+ | |||
+ | <code bash> | ||
+ | > sort -k2,2 example.txt | ||
+ | 123 Bianchi Bianchi 30.0 | ||
+ | 234 Bianchi Gianna 17.0 | ||
+ | 12 Rossi Stefania 21.5 | ||
+ | 408 Rossi Giulia 30.0 | ||
+ | </ | ||
+ | |||
+ | <code bash> | ||
+ | > sort -k2,2 -k4,4n example.txt | ||
+ | 234 Bianchi Gianna 17.0 | ||
+ | 123 Bianchi Bianchi 30.0 | ||
+ | 12 Rossi Stefania 21.5 | ||
+ | 408 Rossi Giulia 30.0 | ||
+ | </ | ||
+ | |||
+ | <code bash> | ||
+ | > sort -R example.txt | ||
+ | 234 Bianchi Gianna 17.0 | ||
+ | 123 Bianchi Bianchi 30.0 | ||
+ | 12 Rossi Stefania 21.5 | ||
+ | 408 Rossi Giulia 30.0 | ||
+ | </ | ||
+ | |||
+ | ===== '' | ||
+ | |||
+ | (the '' | ||
+ | |||
+ | <code bash> | ||
+ | > egrep -e " | ||
+ | 408 Rossi Giulia 30.0 | ||
+ | 12 Rossi Stefania 21.5 | ||
+ | 234 Bianchi Gianna 17.0 | ||
+ | </ | ||
+ | |||
+ | <code bash> | ||
+ | > egrep -e " | ||
+ | 408 Rossi Giulia 30.0 | ||
+ | 12 Rossi Stefania 21.5 | ||
+ | 234 Bianchi Gianna 17.0 | ||
+ | </ | ||
+ | |||
+ | <code bash> | ||
+ | > egrep -n -e " | ||
+ | 3:234 Bianchi Gianna 17.0 | ||
+ | 4:123 Bianchi Bianchi 30.0 | ||
+ | </ | ||
+ | |||
+ | <code bash> | ||
+ | > egrep -n -v -e " | ||
+ | 1:408 Rossi Giulia 30.0 | ||
+ | 2:12 Rossi Stefania 21.5 | ||
+ | </ | ||
+ | |||
+ | <code bash> | ||
+ | > egrep -H -A 1 -B 0 -e " | ||
+ | example.txt: | ||
+ | example.txt-234 Bianchi Gianna 17.0 | ||
+ | </ | ||
+ | |||
+ | <code bash> | ||
+ | > egrep -e " | ||
+ | 408 Rossi 30.0 | ||
+ | 12 Rossi 21.5 | ||
+ | 123 Bianchi 30.0 | ||
+ | </ |