5.重定向和管道 練習
1 、將/etc/issue 文件中的內容轉換為大寫后保存至/tmp/issue.out 文件中
cat /etc/issue |tr 'a-z' 'A-Z' >/tmp/issue.out
2 、將當前系統登錄用戶的信息轉換為大寫后保存至/tmp/who.out 文件中
who |tr 'a-z' 'A-Z' >/tmp/who.out
who |tr [[:lower:]] [[:upper:]] >/tmp/who.out
3 、一個linux 用戶給root 發郵件,要求郵件標題為”help” ,郵件正文如下:
Hello, I am 用戶名,the system version is here,please help me to
check it ,thanks!
操作系統版本信息
mail -s "help" root <<eof
> hello I am 'whoami','
> the system version is here ,
> please help me to check ist,
> Thanks!
> eof
4 、將/root/ 下文件列表,顯示成一行,并文件名之間用 空格 隔開
ls /root/ >f2
cat f2 |tr '\n' ' :'
5 、file1 文件 的 內容為:”1 2 3 4 5 6 7 8 9 10” 計算出所有數字的總和
echo "1 2 3 4 5 6 7 8 9 10"|tr ' ' '+'|bc
echo $[`echo "1 2 3 4 5 6 7 8 9 10"|tr ' ' '+'`]
6 、刪除Windows 文本文件中的'^M' 字符
cat an.txt | tr -d '\r'
7 、處理字符串“xt.,l 1 jr#!$mn 2 c*/fe 3 uz 4 ”,只保留其中的數字
和 空格
echo 'xt.,l 1 jr#!$mn 2 c*/fe 3 uz 4' |tr -cd '[:digit:] \n'
echo 'xt.,l 1 jr#!$mn 2 c*/fe 3 uz 4' |tr -cd '[0-9] \n'
8 、將PATH 變量每個目錄顯示在獨立的一行
echo $PATH | tr ':' '\n'echo 'xt.,l 1 jr#!$mn 2 c*/fe 3 uz 4' |tr -cd '[:digit:] \n'
9 、刪除指定文件的空行
cat f1 | -s '\n'
10 、將文件中每個單詞(字母)顯示在獨立的一行,并無空行
cat /f1 |tr -cd '[:alpha:]''\n'
原創文章,作者:AN0519,如若轉載,請注明出處:http://www.www58058.com/28108