Syntax:
The syntax of tr command is:$ tr [OPTION] [SET1] [SET2]
Examples:
1. Convert lower case to upper case:
$ tr [:lower:] [:upper:]
2. Translate braces into parenthesis
$ tr '{}' '()' < inputfile > outputfile
3. Translate white-space to tabs
$ tr [:space:] '\t'
4. Squeeze repetition of characters using -s
$ tr -s [:space:] '\t'
5. Delete specified (digits) characters using -d option
$ tr -d [:digit:]
6. Complement the sets using -c option
$ tr -cd [:digit:]
7. Remove all non-printable character from a file
$ tr -cd [:print:] < file.txt
8. Join all the lines in a file into a single line
$ tr -s '\n' ' ' < file.txt
9. To replace every sequence of one or more new lines with a single new line
$ tr -s '\n' < textfile > newfile
10.
To delete all NULL characters from a file
$ tr -d '\0' < textfile > newfile
-------------------------------------------------------------------------------
No comments:
Post a Comment