1、将/etc/issue文件中的内容转换为大写后保存至/tmp/issue.out文件中
tr 'a-z' 'A-Z' < /etc/issue >/tmp/issue
2、将当前系统登录用户的信息转换为大写后保存至/tmp/who.out文件中
w(who) | tr 'a-z' 'A-Z' > /tmp/who.out
3、一个linux用户给root发邮件,要求邮件标题为”help”,邮件正文如下:
Hello, I am 用户名,the system version is here,pleasehelp me to check it ,thanks!
操作系统版本信息
echo -e "hello ,I am `whoami`,the system version is here ,please help me to check it ,thanks! \n`cat /etc/centos-release`" > /tmp/help
mail -s help root < /tmp/help
4、将/root/下文件列表,显示成一行,并文件名之间用空格隔开
ls -am /root | tr -t ',' ' ' m选项表示以逗号分隔
5、file1文件的内容为:”1 2 3 4 5 6 7 8 9 10” 计算出所有数字的总和
echo "1 2 3 4 5 6 7 8 9 10"> tmp1 | cat /tmp/1 |tr -s ' '| tr -t ' ' '+'| bc
6、删除Windows文本文件中的'^M'字符
cat file | tr -d "\r" > file
7、处理字符串“xt.,l 1 jr#!$mn2 c*/fe3 uz4”,只保留其中的数字和空格
echo "xt.,l 1 jr#exitmn2 c*/fe3 uz4" | tr -d "[:alpha:][:punct:]"
8、将PATH变量每个目录显示在独立的一行
echo $PATH | tr -t ":" "\n"
9、删除指定文件的空行
cat file | tr -s "\n"
10、将文件中每个单词(字母)显示在独立的一行,并无空行
cat file | tr -s "[:space:] " | tr -t " " "\n" | tr -s "\n"
转载于:https://blog.51cto.com/11763733/1832096