In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to use the tr command in Linux, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand.
Linux common commands tr commands can replace, compress, and delete characters from standard input. It can change one set of characters into another, and is often used to write beautiful one-line commands.
Tr replaces, compresses and deletes characters
Syntax tr (option) (parameter) option-c or-- complerment: replace all characters that do not belong to the first character set;-d or-- delete: delete all characters belonging to the first character set;-s or-- squeeze-repeats: represent consecutive repeated characters as a single character;-t or-- truncate-set1: first delete more characters in the first character set than in the second character set. Parameter character set 1: specifies the original character set to be converted or deleted. When performing a conversion operation, you must use the parameter character set 2 to specify the target character set for the conversion. However, the parameter "character set 2" is not required to perform the delete operation.
Character set 2: specifies the target character set to convert to.
Instance converts input characters from uppercase to lowercase:
Echo "HELLO WORLD" | tr 'Amurz', 'Amurz' hello world'A-Z' and 'Amurz' are collections, and collections can be made on their own. For example, 'ABD-}', 'bB.,',' 'Amuri h' and' a-c0-9 'all belong to collections. You can use'\ n','\ tones' and other ASCII characters in the collection.
Use tr to delete characters:
Echo "hello 123 world 456" | tr-d'0-9 'hello world converts tabs to spaces:
Cat text | tr'\ t''character set complement, which removes all characters from the input text that are not in the complement set:
Echo aa.,a 1 b#$bb 2 c*/cc 3 ddd 4 | tr-d-c'0-9\ n'1 234 in this example, the complement contains the number 0x9, space, and newline character\ n, so it is not deleted, all other characters are deleted.
By compressing characters with tr, you can compress characters that are repeated in the input:
Echo "thissss is a text linnnnnnne." | tr-s' sn' this is a text line. Ingenious use of tr to add numbers:
Echo 1 2 3 4 5 6 7 8 9 | xargs-N1 | echo $[$(tr'\ n''+') 0] Delete the'^ M' character "caused" by the Windows file:
Cat file | tr-s "\ r"\ n" > new_file or cat file | tr-d "\ r" > the character classes that new_filetr can use:
[: alnum:]: letters and numbers [: alpha:]: letters [: cntrl:]: control (non-printing) characters [: digit:]: numbers [: graph:]: graphic characters [: lower:]: lowercase characters [: print:]: printable characters [: punct:]: punctuation marks [: space:]: blank characters [: upper:]: uppercase letters [: xdigit:]: hexadecimal characters:
Tr'[: lower:]'[: upper:] Thank you for reading this article carefully. I hope the article "how to use tr commands in Linux" shared by the editor will be helpful to everyone. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.