Tr

From Wiki
Jump to navigation Jump to search

translate or delete characters

http://linux.die.net/man/1/tr

http://www.cyberciti.biz/faq/how-to-use-linux-unix-tr-command/


Count the number of slashes in a string:

echo "/incoming/data/" | tr -dc '/' | wc -c  # gives 3

Convert to uppercase:

echo 'linux' | tr "[:lower:]" "[:upper:]"  # LINUX
echo 'linux' | tr "a-z" "A-Z"              # LINUX

Remove all non-printable characters from myfile.txt

tr -cd "[:print:]" < myfile.txt