1、将/etc/issue文件中的内容转换为大写后保存至/tmp/issue.out文件中
[root@localhost ~]# cp /etc/issue ./ [root@localhost ~]# cat issue | tr ‘a-z‘ ‘A-Z‘ > /tmp/issue.out [root@localhost ~]# cat /tmp/issue.out CENTOS RELEASE 6.8 (FINAL) KERNEL \R ON AN \M TTY IS \L HOSTNAME IS \N TIME IS \T
2、将当前系统登录用户的信息转换为大写后保存至/tmp/who.out文件中
[root@localhost ~]# who | tr ‘a-z‘ ‘A-Z‘ > /tmp/who.out [root@localhost ~]# cat /tmp/who.out ROOT TTY1 2008-08-09 19:54 ROOT PTS/1 2008-08-10 01:07 (10.10.10.1)
3、一个linux用户给root发邮件,要求邮件标题为”help”,邮件正文如下:
Hello, I am 用户名,the system version is here,pleasehelp me to check it ,thanks!
操作系统版本信息
[ping@localhost ~]$ echo "Hello, I am $(whoami) the system version is here, please help me to check it. $(cat /etc/redhat-release)" | mail -s "help" root [ping@localhost ~]$ logout You have new mail in /var/spool/mail/root [root@localhost ~]# mail >N 8 ping@localhost.local Sun Aug 10 06:46 18/690 "help" & 8 Message 8: From ping@localhost.localdomain Sun Aug 10 06:46:24 2008 Return-Path: <ping@localhost.localdomain> X-Original-To: root Delivered-To: root@localhost.localdomain Date: Sun, 10 Aug 2008 06:46:24 +0800 To: root@localhost.localdomain Subject: help User-Agent: Heirloom mailx 12.4 7/29/08 Content-Type: text/plain; charset=us-ascii From: ping@localhost.localdomain Status: R Hello, I am ping the system version is here, please help me to check it. CentOS release 6.8 (Final)
4、将/root/下文件列表,显示成一行,并文件名之间用空格隔开
[root@localhost ~]# ls /root | tr ‘\n‘ ‘ ‘ A anaconda-ks.cfg a.txt b c d install.log install.log.syslog issue manpages-zh-1.5.1.tar.gz test1 test10 test11
5、file1文件的内容为:”1 2 3 4 5 6 7 8 9 10” 计算出所有数字的总和
[root@localhost ~]# echo "1 2 3 4 5 6 7 8 9 10" | tr ‘ ‘ ‘+‘ | bc 55
6、删除Windows文本文件中的‘^M‘字符
[root@localhost ~]# cat -A a.txt aaaaaaaa^M$ bbbbbbbbbbbbbbb^M$ ccccccccccccccccccc^M$ vvvvvvvvvvvvvvvvvvvvvvvvv^M$ [root@localhost ~]# cat a.txt | tr -d ‘\r‘ >new.txt | cat new.txtaaaaaaaa bbbbbbbbbbbbbbb ccccccccccccccccccc vvvvvvvvvvvvvvvvvvvvvvvvv
7、处理字符串“xt.,l 1 jr#!$mn2 c*/fe3 uz4”,只保留其中的数字和空格
[root@localhost ~]# echo "xt.,l 1 jr#ifconfigmn 2 c*/fe 3 uz 4" | tr -d ‘[[:alpha:]][[:punct:]]‘ 1 2 3 4
8、将PATH变量每个目录显示在独立的一行
[root@localhost ~]# echo $PATH | tr ‘:‘ ‘\n‘ /usr/lib64/qt-3.3/bin /usr/local/sbin /usr/local/bin /sbin /bin /usr/sbin /usr/bin /root/bin
9、删除指定文件的空行
[root@localhost ~]# cat file2 aaaa bbbb cccc dddd [root@localhost ~]# cat file2 | tr -s ‘\n‘ aaaa bbbb cccc dddd
10、将文件中每个单词(字母)显示在独立的一行,并无空行
[root@localhost ~]# cat file2 aaaa bbbb cccc dddd [root@localhost ~]# tr -cs ‘[:alpha:]‘ ‘\n‘ < file2 aaaa bbbb cccc dddd
原文地址:http://suifengsky.blog.51cto.com/11393684/1833162