练习题1:将/etc/issue文件中的内容转换为大写后保存至/tmp/issue.out文件中
[[email protected] ~]# tr [:lower:] [:upper:] > /tmp/issue.out < /etc/issue [[email protected] ~]# tr ‘a-z‘ ‘A-Z‘ > /tmp/issue.out < /etc/issue使用tee在输出到文件的同时显示 [[email protected] ~]# tr ‘a-z‘ ‘A-Z‘ < /etc/issue | tee /tmp/issue.out CENTOS RELEASE 6.8 (FINAL) KERNEL \R ON AN \M \L \T \U
练习题2:将当前系统登录用户的信息转换为大写后保存至/tmp/who.out文件中
[[email protected] wu]# who -a | tr [:lower:] [:upper:] > /tmp/who.out [[email protected] ~]# who -a | tr ‘a-z‘ ‘A-Z‘ > /tmp/who.out
练习题3:一个linux用户给root发邮件,要求邮件题为”help”,邮件正文如下:Hello, I am 用户名,the systemversion is here,pleasehelp me to check it,thanks!操作系统版本信息
echo "Hello, I am $USER, the system version is here, please help me to check it, thanks! > `cat /etc/centos-release` " | mail -s help root
练习题4:将/root/下文件列表,显示成一行,并文件名之间用空格隔开。
M1: echo `ls /root` al3a Documents install.log.syslog Music Templates M2: [[email protected] ~]# ls /root | tr ‘\n‘ ‘ ‘
练习题5:file1文件的内容为:”1 2 3 4 5 6 7 8 9 10” 计算出所有数字的总和
[[email protected] ~]# seq -s ‘ ‘ 1 9 > f [[email protected] ~]# cat f1 2 3 4 5 6 7 8 9 [[email protected] ~]# echo $((`tr ‘ ‘ ‘+‘ < f`)) 45
练习题6:删除Windows文本文件中的‘^M‘字符
tr -d "\r" < oldfile > newfile # "^M",需要使用Ctrl + V + Ctrl + M键入
练习题7:处理字符串“xt.,l 1 jr#!$mn2 c*/fe3 uz4”,只保留其中的数字和空格
[[email protected] ~]# echo ‘xt.,l 1 jr#!$mn2 c*/fe3 uz4‘ > f [[email protected] ~]# tr -cd [:digit:] < f 1234
时间: 2024-10-10 03:01:44