Tr: Difference between revisions

From Wiki
Jump to navigation Jump to search
Created page with '{{lowercase title}} Count the number of slashes in a string: <pre> echo "/incoming/data/" | tr -dc '/' | wc -c </pre>'
 
No edit summary
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
{{lowercase title}}
{{lowercase title}}
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:
Count the number of slashes in a string:
<pre>
<pre>
echo "/incoming/data/" | tr -dc '/' | wc -c
echo "/incoming/data/" | tr -dc '/' | wc -c # gives 3
</pre>
 
Convert to uppercase:
<pre>
echo 'linux' | tr "[:lower:]" "[:upper:]"  # LINUX
echo 'linux' | tr "a-z" "A-Z"              # LINUX
</pre>
 
Remove all non-printable characters from myfile.txt
<pre>
tr -cd "[:print:]" < myfile.txt
</pre>
</pre>

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