cheat-fork-echo/cheat/cheatsheets/tr

23 lines
592 B
Text
Raw Permalink Normal View History

2015-10-07 05:34:01 +02:00
#replace : with new line
2015-10-07 05:39:27 +02:00
echo $PATH|tr ":" "\n" #equivalent with:
2015-10-07 05:34:01 +02:00
echo $PATH|tr -t ":" \n
2015-10-07 15:14:45 +02:00
#remove all occurance of "ab"
echo aabbcc |tr -d "ab"
2015-10-07 15:20:06 +02:00
#ouput: cc
2015-10-07 15:14:45 +02:00
2015-10-07 05:34:01 +02:00
#complement "aa"
echo aabbccd |tr -c "aa" 1
2015-10-07 15:14:45 +02:00
#output: aa11111 without new line
#tip: Complement meaning keep aa,all others are replaced with 1
2015-10-07 05:34:01 +02:00
#complement "ab\n"
echo aabbccd |tr -c "ab\n" 1
#output: aabb111 with new line
2015-10-07 15:14:45 +02:00
#Preserve all alpha(-c). ":-[:digit:] etc" will be translated to "\n". sequeeze mode.
2015-10-07 05:34:01 +02:00
echo $PATH|tr -cs "[:alpha:]" "\n"
#ordered list to unordered list
2015-10-07 15:14:45 +02:00
echo "1. /usr/bin\n2. /bin" |tr -cs " /[:alpha:]\n" "+"