Convert to uppercase
echo "Hi There" | tr 'A-Z' 'a-z'
gives
hi there
put individual words on individual lines
echo "Hello sailor" | tr -c 'A-Za-z' '\012'
gives...
Hello
sailor
put individual words on individual lines but don't repeat the carriage return
Note: without the
s, you would have a carriage return for each space. Instead, it squashes repeats...but note, contrary to what I read on the
man page, it does not squash
Heello
echo "Heello sailor" | tr -sc 'A-Za-z' '\012'
Heello
sailor
...so, it must just squash the last pattern, proven by this...
echo "Heello sailor" | tr -s 'A-Za-z'
Helo sailor
Replace all chars but the ones specified
echo "Hello sailor" | tr -c 'A-Za-df-z' '\012'
replaces all chars with a carriage return EXCEPT 'e'
gives...
H
llo
sailor
Sorting tricks
-
sort +1 - sorts by field 1 - saves a pipe to awk!
Find word frequency
cat | tr -sc 'A-Za-z' '\012' | tr 'A-Z' 'a-z' | sort | uniq -c | sort -n
--
MattWalsh - 11 Mar 2006