- The tr utility copies the given input to produced the output with substitution or deletion of selected characters.
- It takes as parameters two sets of characters, and replaces occurrences of the characters in the first set with the corresponding elements from the other set
Syntax :
tr [options] "set1" "set2"
tr "set1" "set2" < input.txt
tr "set1" "set2" < input.txt > output.txt
Translate the word 'linux' to upper-case:
$ echo "linux"|tr "a-z" "A-Z"
LINUX
Remove all two more successive blank spaces from a copy of the text in a file called input.txt
tr -s ' ' ' ' < input.txt
To replace every sequence of one or more new lines with a single new line:
tr -s '\n' < input.txt
To replace every sequence of one or more new lines with a single new line and remove the consecutive spaces in the word.
tr -s '\n' < input.txt |tr -s ' ' ' '
Delete the special characters in a file
To remove the carriage return from the carriage return/newline pair used by Microsoft OSes as a line terminator
tr -d '\r' < pc.file > unix.file
To delete all NULL characters from a file:
tr -d '\0' < textfile > newfile
To replace every sequence of characters in the <space> character class with a single : (colon) character, enter:
tr -s '[:space:]' '[\:*]' < in_file
No comments:
Post a Comment