Tr: Difference between revisions

From Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
Line 1: Line 1:
{{lowercase title}}
{{lowercase title}}
tr - translate or delete characters
translate or delete characters


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

Latest revision as of 18:08, 20 April 2011

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