🖥️tr

➡️This is a command-line reference manual for commands and command combinations that you don’t use often enough to remember it. This cheatsheet explains the tr command with important options and switches using examples.

▁ ▂ ▃ ▄ ꧁ 🔴☠ COMMANDLINE-KUNGFU WITH CHEATSHEETS ☠🔴꧂▅ ▃ ▂ ▁

#                ████████╗██████╗ 
#                ╚══██╔══╝██╔══██╗
#                   ██║   ██████╔╝
#                   ██║   ██╔══██╗
#                   ██║   ██║  ██║
#                   ╚═╝   ╚═╝  ╚═╝
                                 

#replace : with new line
echo $PATH|tr ":" "\n" #equivalent with:
echo $PATH|tr -t ":" \n 

#remove all occurance of "ab"
echo aabbcc |tr -d "ab"
#ouput: cc

#complement "aa"
echo aabbccd |tr -c "aa" 1
#output: aa11111 without new line
#tip: Complement meaning keep aa,all others are replaced with 1

#complement "ab\n"
echo aabbccd |tr -c "ab\n" 1
#output: aabb111 with new line

#Preserve all alpha(-c). ":-[:digit:] etc" will be translated to "\n". sequeeze mode.
echo $PATH|tr -cs "[:alpha:]" "\n" 

#ordered list to unordered list
echo "1. /usr/bin\n2. /bin" |tr -cs " /[:alpha:]\n" "+"

tr -d '\r' < vmargs.txt | tr '\n' ' '
#  Join lines and separate with spaces Read vmargs.txt, which is a text file that could either be DOS-style (\r\n) or UNIX-style (\n) line endings and join the lines with a space separator. Can this be shortened/made more elegant?

tr [:upper:] [:lower:]
# The 'tr' command can be used to quickly convert uppercase to lowercase and vice versa. This is done with:

tr -cd , < file.txt | wc -m 
# Count the number of commas (,) in a text file.

# Format a list of emails so that when you paste them into Outlook (ugh!), it breaks them up into individual addrs
tr $'\n' \; < email-list

#  bash compress css - bash compress css: gistfile1.txt 
tr '[:space:][:cntrl:]' ' ' | tr -s ' ' | \
	sed -e 's| \?: \?|:|g' \
		-e 's| \?{ \?|{|g' \
		-e 's| \?} \?|}|g' \
		-e 's| \?; \?|;|g' \
		-e 's| \?, \?|,|g' \
		-e 's| \?!|!|g' \
		-e 's|;}|}|g'

# tr Command
#-------------------------------------------------///
# This tool translates or deletes characters from standard input and writes results to standard output. The syntax for using tr is as follows:

tr options set1 set2

# Take a look at the examples below, in the first command, set1( [:upper:] ) represents the case of input characters (all upper case). Then set2([:lower:]) represents the case in which the resultant characters will be. It’s same thing in the second example and the escape sequence \n means print output on a new line:

echo "WWW.TECMINT.COM" | tr [:upper:] [:lower:]
www.tecmint.com

echo "news.tecmint.com" | tr [:lower:] [:upper:]
NEWS.TECMINT.COM

# Show the PATH, one directory per line (part 2)   -   Here is another way to show the path, one directory per line. The command `tr` translates the colon into the new line, taking input from the $PATH variable Show Sample Output
tr : \\n <<<$PATH

## Verschlüsselung mit tr ##
#--------------------------#
tr 'e' 'X' < ameisen.txt
# in hamburg lXbtXn zwXi amXisXn,

tr 'a-z' 'A-Z'
# IN HAMBURG LEBTEN ZWEI AMEISEN,

tr 'a-z' 'n-za-m' < ameisen
# va unzohet yrogra mjrv nzrvfra,

# In Datei Abspeichern
tr 'a-z' 'n-za-m' < ameisen > ameisen_kodiert

# Remove Line Breaks with tr
# I had a text file with multiple lines of input that I was manipulating using awk and sed but I found the following 'tr' command easiest to remove the line breaks:
cat input.txt | tr -d '\n'

#==============================##==============================#
# CMD TR						       #
#==============================##==============================#

 
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░

  █║▌│║█║▌★ KALI ★ PARROT ★ DEBIAN 🔴 PENTESTING ★ HACKING ★ █║▌│║█║▌

              ██╗ ██╗ ██████╗  ██████╗ ██╗  ██╗███████╗██████╗
             ████████╗██╔══██╗██╔═══██╗╚██╗██╔╝██╔════╝██╔══██╗
             ╚██╔═██╔╝██║  ██║██║   ██║ ╚███╔╝ █████╗  ██║  ██║
             ████████╗██║  ██║██║   ██║ ██╔██╗ ██╔══╝  ██║  ██║
             ╚██╔═██╔╝██████╔╝╚██████╔╝██╔╝ ██╗███████╗██████╔╝
              ╚═╝ ╚═╝ ╚═════╝  ╚═════╝ ╚═╝  ╚═╝╚══════╝╚═════╝

               █║▌│║█║▌ WITH COMMANDLINE-KUNGFU POWER █║▌│║█║▌

░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░