"Drip" LINUX TR command __linux

Source: Internet
Author: User
Tags character classes first string
It is said that the TR command is a fine gadget at the home of the Linux line, and can be used to write many graceful single-line commands. Use: Tr-c-d-s ["String1_to_translate_from"] ["string2_to_translate_to"] parameter:-c #使用string1的补集, request string for ascii-d # Delete all input characters in string1-s #删除所有重复出现的字符序列, only the first one, the string to be repeated will be compressed into the first string
#大小转为小写
> echo "Hello World" |tr "A-Z" "A-Z"
Hello World
#删除数字
> echo "Hello 134 World 565" |tr-d "1- 9 "
Hello World
#-c", representing the deletion of non-numeric, ' \ n ' linefeed
> Echo ' Hello 134 World 565 ' |tr-d-C ' 1-9\n '
134565
#删除非数字  , spaces, ' \ n ' linefeed
> Echo ' Hello 134 World 565 ' |tr-d-c ' 1-9 \ n '
134 565
#压缩空格, only one
> echo "Hello World" Hello shell "|tr-s" Hello World
Hello Shell
#用tr命令做加法
> Cat sum.txt
1
2
3
4< C20/>5
> Cat sum.txt |echo $[$ (tr ' \ n ' + ') 0]
#cat sum.txt|tr ' \ n ' + ' replace all ' \ n ' with a ' + ', output 1+2+3+4+5+ , and finally a 0 becomes $[1+2+3+4+5+0] gets the

character class: TR can also use character classes, as
follows     alnum
#字母和数字 Alpha     #字母
Cntrl The     #控制 (nonprinting) character
digit     #数字
graph     #图形
lower     #小写字母
Upper     #大写字母
Print     #可打印字符
punct     #标点符号
space     #空白字符
xdigit     #十六进制字符
>tr ' [: Lower:] ' [: Upper:] '
lowercase to uppercase


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.