2015-03-12 08:41:54 +00:00
|
|
|
# tr
|
|
|
|
|
2016-01-07 17:31:27 +00:00
|
|
|
> Translate characters - run replacements based on single characters and character sets.
|
2015-03-12 08:41:54 +00:00
|
|
|
|
2016-01-07 17:31:27 +00:00
|
|
|
- Replace all occurrences of a character in a file, and print the result:
|
2015-03-12 08:41:54 +00:00
|
|
|
|
2015-03-14 11:05:19 +00:00
|
|
|
`tr {{find_characters}} {{replace_characters}} < {{filename}}`
|
2015-03-12 08:41:54 +00:00
|
|
|
|
2016-01-07 17:31:27 +00:00
|
|
|
- Map each character of the first set to the corresponding character of the second set:
|
2015-03-14 11:05:19 +00:00
|
|
|
|
|
|
|
`tr 'abcd' 'jkmn' < {{filename}}`
|
|
|
|
|
2017-05-12 10:29:18 +01:00
|
|
|
- Delete all occurrences of the specified set of characters from the input:
|
2015-03-14 11:05:19 +00:00
|
|
|
|
|
|
|
`tr -d '{{input_characters}}'`
|
|
|
|
|
2016-01-07 17:31:27 +00:00
|
|
|
- Compress a series of identical characters to a single character:
|
2015-03-14 11:05:19 +00:00
|
|
|
|
|
|
|
`tr -s '\n'`
|
|
|
|
|
2016-01-07 17:31:27 +00:00
|
|
|
- Translate the contents of the file to upper-case and print result:
|
2015-03-12 08:41:54 +00:00
|
|
|
|
|
|
|
`tr "[:lower:]" "[:upper:]" < {{filename}}`
|
|
|
|
|
2016-01-07 17:31:27 +00:00
|
|
|
- Strip out non-printable characters from the file and print result:
|
2015-03-12 08:41:54 +00:00
|
|
|
|
|
|
|
`tr -cd "[:print:]" < {{filename}}`
|