grep、wc和管道符 学会啦!

1.grep命令

从文件中通过关键字过滤文件行

语法: grep [-n] 关键字 文件路径

·选项n,可选,表示在结果中显示匹配的行号

·参数,关键字,必填,表示过滤的关键字,带有空格或其它特殊符号,建议使用""将关键字包围起来

·参数,文件路径,必填,表示要过滤内容的文件路径,可作为内容输入端口

wendy@wendydeMacBook-Air ~ % touch test.txt                                                                                                                                                                                  wendy@wendydeMacBook-Air ~ % cat test.txt
Wendy is a great woman.
The great code is 003456.%                                                                                                                                                                                    wendy@wendydeMacBook-Air ~ % grep -n "great" test.txt 
1:Wendy is a great woman.
2:The great code is 003456.

2.wc命令做数量统计

统计文件的行数、单词数量等

语法: wc [-c -m -w]  文件路径

·选项 -c 统计bytes数量

·选项 -m 统计字符数量

·选项 -l 统计行数

·选项 -w 统计单词数量

·参数 文件路径,被统计的文件,可作为内容输入端口

wendy@wendydeMacBook-Air ~ % wc test.txt
       1      10      49 test.txt
wendy@wendydeMacBook-Air ~ % wc -c test.txt 
      49 test.txt
wendy@wendydeMacBook-Air ~ % wc -m test.txt
      49 test.txt
wendy@wendydeMacBook-Air ~ % wc -l test.txt
       1 test.txt
wendy@wendydeMacBook-Air ~ % wc -w test.txt
      10 test.txt

3.管道符(|)

|:将管道符左边命令的结果,作为右边命令的输入

wendy@wendydeMacBook-Air ~ % cat test.txt | grep great test.txt
Wendy is a great woman.
The great code is 003456.

完结 🎉 继续更新 加个关注收藏一下叭~

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一只学习python的兔子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值