标签:tr
1、将/etc/issue文件中的内容转换为大写后保存至/tmp/issue.out文件中
[root@centos7 tmp]# cat /etc/issue | tr [a-z] [A-Z] > /tmp/issue.out [root@centos7 tmp]# cat /tmp/issue.out \S KERNEL \R ON AN \M
或者
[root@centos7 tmp]# tr [a-z] [A-Z] < /etc/issue > /tmp/issue.out [root@centos7 tmp]# cat /tmp/issue.out \S KERNEL \R ON AN \M
2、将当前系统登录用户的信息转换为大写后保存至/tmp/who.out文件中
[root@centos7 tmp]# who | tr [a-z] [A-Z] > /tmp/who.out [root@centos7 tmp]# cat /tmp/who.out USER :0 2016-07-21 14:55 (:0) USER PTS/0 2016-07-29 10:32 (:0) ROOT PTS/1 2016-07-31 09:25 (10.1.250.29) ROOT PTS/2 2016-07-30 11:07 (10.1.250.29) ROOT PTS/6 2016-07-30 10:59 (10.1.250.29)
3、一个linux用户给root发邮件,要求邮件标题为”help”,邮件正文如下:
Hello, I am 用户名,the system version is here,pleasehelp me to check it ,thanks!
操作系统版本信息
[user@centos7 ~]$ vim information Hello,I am user,the system version is here,please help me to check it,thanks! cat /etc/centos-release [user@centos7 ~]$ mail -s help root < informatio
4、将/root/下文件列表,显示成一行,并文件名之间用空格隔开
[root@centos7 tmp]# cd [root@centos7 ~]# pwd /root [root@centos7 ~]# ls anaconda-ks.cfg f1 initial-setup-ks.cfg new [root@centos7 ~]# ls -1 | tr ‘\n‘ ‘ ‘ anaconda-ks.cfg f1 initial-setup-ks.cfg new
5、file1文件的内容为:”1 2 3 4 5 6 7 8 9 10” 计算出所有数字的总和
[root@centos7 ~]# echo "1 2 3 4 5 6 7 8 9 10" > file1 [root@centos7 ~]# cat file1 | tr ‘ ‘ ‘+‘ | bc 55
或者
[root@centos7 ~]# echo $(seq 1 10) > /file1 [root@centos7 ~]# for I in $(cat file1); do sum=$[$sum+$I]; done; echo $sum 55
6、删除Windows文本文件中的‘^M‘字符
[root@centos7 ~]# echo Windows | tr -d W indows
7、处理字符串“xt.,l 1 jr#!$mn2 c*/fe3 uz4”,只保留其中的数字和空格
[root@centos7 ~]# echo "xt., 1 jr#trmn2 c*/fe3 uz4" | tr -d [:punct:][:alpha:] 1 2 3 4
8、将PATH变量每个目录显示在独立的一行
[root@centos7 ~]# echo $PATH | tr ‘:‘ ‘\n‘ /usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /root/bin
9、删除指定文件的空行
[root@centos7 ~]# cat /etc/issue \S Kernel \r on an \m [root@centos7 ~]# cat /etc/issue | tr -s ‘\n‘ \S Kernel \r on an \m [root@centos7 ~]#
10、将文件中每个单词(字母)显示在独立的一行,并无空行
[root@centos7 ~]# cat /etc/issue | tr -s ‘\n‘ | tr ‘\n‘ ‘ ‘ | tr ‘ ‘ ‘\n‘ \S Kernel \r on an \m [root@centos7 ~]#
或者
[root@centos7 ~]# cat /etc/issue | tr ‘ ‘ ‘\n‘ | tr -s ‘\n‘ \S Kernel \r on an \m [root@centos7 ~]#
本文出自 “dmwing” 博客,请务必保留此出处http://dmwing.blog.51cto.com/11607397/1832340
标签:tr
原文地址:http://dmwing.blog.51cto.com/11607397/1832340