shell脚本 之 tee tr

tee :就是将输出定位到文件中,类似于 > . 主要参数 -a
-a:追加的方式 等同于 >>
默认的情况下是覆盖。若是文件已经存在的话!
ping www.sina.com.cn |tee sina < ======= > ping www.sina.com.cn > tee sina
ping www.sina.com.cn |tee -a sina < ======= > ping www.sina.com.cn >> tee sina
唯一的区别时才用tee命令,我们可以在后面继续跟管道
ping www.sina.com.cn |tee sina |xargs -F “:” awk ‘{print $1}’

tr :translate or delete characters
语法:tr 需要替换文本 目标文本
主要参数 -d
先生成一个测试脚本 ping www.sina.com.cn |tee trTest
看下生成的文本:
inter12@inter12:~/myshell/shell/tr$ cat trTest
PING auriga.sina.com.cn (61.172.201.195) 56(84) bytes of data.
64 bytes from 61.172.201.195: icmp_req=1 ttl=242 time=3.97 ms
64 bytes from 61.172.201.195: icmp_req=2 ttl=242 time=3.89 ms
64 bytes from 61.172.201.195: icmp_req=3 ttl=242 time=3.85 ms
64 bytes from 61.172.201.195: icmp_req=4 ttl=242 time=3.92 ms
64 bytes from 61.172.201.195: icmp_req=5 ttl=242 time=3.87 ms

替换操作
cat trTest|tr “from” “to”
——————————————
inter12@inter12:~/myshell/shell/tr$ cat trTest |tr “from” “to”
PING auoiga.sina.coo.cn (61.172.201.195) 56(84) bytes ot data.
64 bytes tooo 61.172.201.195: icop_oeq=1 ttl=242 tioe=3.97 os
64 bytes tooo 61.172.201.195: icop_oeq=2 ttl=242 tioe=3.89 os
64 bytes tooo 61.172.201.195: icop_oeq=3 ttl=242 tioe=3.85 os
64 bytes tooo 61.172.201.195: icop_oeq=4 ttl=242 tioe=3.92 os
64 bytes tooo 61.172.201.195: icop_oeq=5 ttl=242 tioe=3.87 os

发现一个很有趣的问题:并不是把from替换成了to。那是否可以得出一个结论,这个是正则进行匹配的!还需要仔细看下!

发表评论?

0 条评论。

发表评论


注意 - 你可以用以下 HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>