Create tr

This commit is contained in:
summer-wu 2015-10-07 11:34:01 +08:00
parent cafa2fb2fd
commit 8eda2266bc

21
cheat/cheatsheets/tr Normal file
View file

@ -0,0 +1,21 @@
#replace : with new line
echo $PATH|tr ":" "\n" #equivalent to:
echo $PATH|tr -t ":" \n
#complement "aa"
echo aabbccd |tr -c "aa" 1
#output: aa11111%
#tip: Complement meaning keep aa,all other is replace with 1
#complement "ab\n"
echo aabbccd |tr -c "ab\n" 1
#output: aabb111 with new line
#preserve all alpha(-c),sequeeze mode instead of character mode
echo $PATH|tr -cs "[:alpha:]" "\n"
#ordered list to unordered list
echo "1 /usr/bin\n2 /bin" |tr -cs "/\n[:alpha:]" "+"
#remove all occurance of "ab"
echo aabbcc |tr -d "ab"