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
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值