Shell脚本攻略学习九之tr命令
2023-09-14 09:13:15 时间
Shell脚本攻略学习笔记九之tr
命令[待完善]
1. tr
命令的使用
- 1.It can be used to perform substitution of characters,deletion of the characters, and squeezing of repeated characters from the standard input.
- 2.tr accepts input only through stdin (standard input) and cannot accept input through command-line arguments.【tr命令仅仅支持标准输入,不支持参数输入】
- 3.tr [options] set1 set2【如果set1 和 set2的长度不等,那么就会出现映射不匹配问题。】
- 4.ROT13 is a well-known encryption algorithm. The ROT13 scheme performs alphabetic rotation of characters for 13 characters.【ROT13 是一个著名的加密算法。字母往后13的字母就是加密后的字符】
如下这个就是使用ROT13作为加密算法使用,同时使用tr
命令测试
[root@server4 backup]# echo "tr came, tr saw, tr conquered." | tr 'a-zA-Z' 'n-za-mN-ZA-M'
ge pnzr, ge fnj, ge pbadhrerq.
- 将文件
file.txt
中的内容作为tr命令的输入,然后将其中的空格转换成+
[root@server4 backup]# tr ' ' '+' < file.txt
hello+spark+\n+hello+hadoop
hello+hive
-d 参数
tr has an option -d to delete a set of characters that appear on stdin by using the specified set of characters to be deleted as follows:
$ cat file.txt | tr -d '[set1]'
#Only set1 is used, not set2【只需要使用set1,不需要参数set2】
- 将字符串中的指定内容删除
[root@server4 backup]# echo "hello 123 world 456" | tr -d '0-9'
hello world
-c 参数
Here,the complement set is the set containing all numerals,space characters,and newline characters.All other characters are removed since -d is used with tr.
-c参数指定的集合会被保留
,
[root@server4 backup]# echo hello 1 char 2 next 4 | tr -d -c '0-9 \n'
1 2 4
Here,the complement set is the set containing all numerals,space characters,and newline characters.All other characters are removed since -d is used with tr.
-s 参数
压缩重复的字符。
tr provides the -s option to squeeze repeating characters from the input.
$[ operation ] performs a numeric operation
[root@server4 shells]# cat sum.txt | echo $[ $(tr '\n' '+') 0 ]
15
相关文章
- 【LINUX 学习】使用find和xargs[转摘自《shell编程和unix命令》]
- 【AIX 命令学习】lsfs 查看显示文件系统信息
- 【AIX 命令学习】删除逻辑卷rmlv 命令!
- 【AIX 命令学习】lsattr 显示一个给定设备或一种设备的属性
- UFLDL 教程学习笔记(四)
- linux shell 脚本攻略学习13--file命令详解,diff命令详解
- linux shell 脚本攻略学习8---md5校验,sort排序,uniq命令详解
- linux命令学习——cat
- linux命令学习——tar
- linux命令学习——ps
- Linux Shell脚本自动化编程实战- shell内置命令 break、continue
- rman命令学习-tina(下)
- linux shell 脚本攻略学习9--rename命令详解
- linux shell 脚本攻略学习5---find命令详解
- tr命令学习
- Linux Shell脚本自动化编程实战- shell内置命令 break、continue
- Python语言学习:利用python语言实现调用内部命令(python调用Shell脚本)—命令提示符cmd的几种方法
- Database之SQLSever:SQLSever数据库管理学习并深入理解SQL命令语句进阶综合篇《初级→中级→高级》(持续更新,建议收藏)
- 数学建模学习(8):最全控制流命令讲解
- linux达人养成计划学习笔记(六)—— 挂载命令
- linux达人养成计划学习笔记(五)—— 关机和重启命令
- linux达人养成计划学习笔记(一)——命令基本格式及文件处理命令
- Shell脚本攻略学习笔记十一之sort命令
- Shell日常学习之comm、sort命令
- 【Python】多线程与多进程学习笔记