Skip to content

Latest commit

 

History

History
58 lines (35 loc) · 824 Bytes

tr.md

File metadata and controls

58 lines (35 loc) · 824 Bytes

tr

tr [options] SET1 [SET2]

translate

Replace characters with other characters

echo abcde | tr "ae" "-"  # → -bcd-

# truncate SET1
echo abcde | tr -t "ae" "-"  # → -bcde

# split pathsep into newlines
echo $PATH | tr ":" "\n"

squeeze (-s)

Remove repeating characters

echo aabbccddee | tr -s "bcd"  # → aabcdee
echo "foo    bar" | tr -s " "  # → foo bar

delete (-d)

Remove characters

echo aabbcc | tr -d "ab"  # -> cc

complement (-c)

Replace anything NOT in SET1

# note the inclusion of newline
echo  "abcde" | tr -c "ae\n" "-"  # -> a---e

examples

# read from /dev/urandom
# discard anything not alphanumeric
# continue until we have 32 chars
tr -cd '[:alnum:]' </dev/urandom | dd bs=32 count=1 2>/dev/null