ITKeyword,专注技术干货聚合推荐

注册 | 登录

linux学习笔记之cat、grep、more命令组合使用

lintaozhou 分享于

2020腾讯云双十一活动,全年最低!!!(领取3500元代金券),
地址https://cloud.tencent.com/act/cps/redirect?redirect=1073

2020阿里云最低价产品入口,含代金券(新老用户有优惠),
地址https://www.aliyun.com/minisite/goods

推荐:linux常用的简单命令(一) ls、pwd、cd、cat/more、grep

以下举例中:蓝色字体为命令输入,红色字体为终端输出。   1.1     查看文件和目录(ls) ls命令是linux最常用的命令,用来显示文件或者目录的相关信息。一般会搭

素材: [root@localhost example]# cat -n 20180514.txt 1 8=imix1.0<SOH>34=1<SOH>35=A<SOH>52=20180514-22:37:45 234<SOH>49=FRONT_SHCH<SOH>56=CDC<SOH>10=123<SOH> 2 3 8=imix1.0<SOH>34=1<SOH>35=A<SOH>52=20180514-22:37:45 234<SOH>49=FRONT_SHCH<SOH>56=CDC<SOH>10=123<SOH> 4 8=imix1.0<SOH>34=1<SOH>35=A<SOH>52=20180514-22:37:45 234<SOH>49=FRONT_SHCH<SOH>56=CDC<SOH>10=123<SOH> 5 8=imix1.0<SOH>34=1<SOH>35=A<SOH>52=20180514-22:37:45 234<SOH>49=FRONT_SHCH<SOH>56=CDC<SOH>10=123<SOH> 6 8=imix1.0<SOH>34=1<SOH>35=A<SOH>52=20180514-22:37:45 234<SOH>49=FRONT_SHCH<SOH>56=CDC<SOH>10=123<SOH> 7 8=imix1.0<SOH>34=1<SOH>35=A<SOH>52=20180514-22:37:45 234<SOH>49=FRONT_SHCH<SOH>56=CDC<SOH>10=123<SOH> 8 8=imix1.0<SOH>34=1<SOH>35=A<SOH>52=20180514-22:37:45 234<SOH>49=FRONT_SHCH<SOH>56=CDC<SOH>10=123<SOH> 9 8=imix1.0<SOH>34=1<SOH>35=AQ<SOH>52=20180514-22:37:45 234<SOH>49=FRONT_SHCH<SOH>56=CDC<SOH>10=123<SOH> 10 8=imix1.0<SOH>34=1<SOH>35=AQ<SOH>52=20180514-22:37:45 234<SOH>49=FRONT_SHCH<SOH>56=CDC<SOH>10=123<SOH> 11 8=imix1.0<SOH>34=1<SOH>35=AP<SOH>52=20180514-22:37:45 234<SOH>49=FRONT_SHCH<SOH>56=CDC<SOH>10=123<SOH> 12 8=imix1.0<SOH>34=1<SOH>35=AR<SOH>52=20180514-22:37:45 234<SOH>49=FRONT_SHCH<SOH>56=CDC<SOH>10=123<SOH> 13 8=imix1.0<SOH>34=1<SOH>35=AE<SOH>52=20180514-22:37:45 234<SOH>49=FRONT_SHCH<SOH>56=CDC<SOH>10=123<SOH> 14 8=imix1.0<SOH>34=1<SOH>35=AE<SOH>52=20180514-22:37:45 234<SOH>49=FRONT_SHCH<SOH>56=CDC<SOH>10=123<SOH> 15 8=imix1.0<SOH>34=1<SOH>35=A<SOH>52=20180514-22:37:45 234<SOH>49=FRONT_SHCH<SOH>56=CDC<SOH>10=123<SOH> 16 8=imix1.0<SOH>34=1<SOH>35=AE<SOH>52=20180514-22:37:45 234<SOH>49=FRONT_SHCH<SOH>56=CDC<SOH>10=123<SOH> 17 8=imix1.0<SOH>34=1<SOH>35=A<SOH>52=20180514-22:37:45 234<SOH>49=FRONT_SHCH<SOH>56=CDC<SOH>10=123<SOH> 18 8=imix1.0<SOH>34=1<SOH>35=AE<SOH>52=20180514-22:37:45 234<SOH>49=FRONT_SHCH<SOH>56=CDC<SOH>10=123<SOH> 19 8=imix1.0<SOH>34=1<SOH>35=AE<SOH>52=20180514-22:37:45 234<SOH>49=FRONT_SHCH<SOH>56=CDC<SOH>10=123<SOH> 20 8=imix1.0<SOH>34=1<SOH>35=A<SOH>52=20180514-22:37:45 234<SOH>49=FRONT_SHCH<SOH>56=CDC<SOH>10=123<SOH> 21 8=imix1.0<SOH>34=1<SOH>35=A<SOH>52=20180514-22:37:45 234<SOH>49=FRONT_SHCH<SOH>56=CDC<SOH>10=123<SOH> 22 8=imix1.0<SOH>34=1<SOH>35=AR<SOH>52=20180514-22:37:45 234<SOH>49=FRONT_SHCH<SOH>56=CDC<SOH>10=123<SOH> 23 8=imix1.0<SOH>34=1<SOH>35=AE<SOH>52=20180514-22:37:45 234<SOH>49=FRONT_SHCH<SOH>56=CDC<SOH>10=123<SOH>

1、搜索出35=A的行 [root@localhost example]# cat -n 20180514.txt |grep '35=A'

1

8=imix1.0<SOH>34=1<SOH>35=A<SOH>52=20180514-22:37:45 234<SOH>49=FRONT_SHCH<SOH>56=CDC<SOH>10=123<SOH>

3

8=imix1.0<SOH>34=1<SOH>35=A<SOH>52=20180514-22:37:45 234<SOH>49=FRONT_SHCH<SOH>56=CDC<SOH>10=123<SOH>

4

8=imix1.0<SOH>34=1<SOH>35=A<SOH>52=20180514-22:37:45 234<SOH>49=FRONT_SHCH<SOH>56=CDC<SOH>10=123<SOH>

5

8=imix1.0<SOH>34=1<SOH>35=A<SOH>52=20180514-22:37:45 234<SOH>49=FRONT_SHCH<SOH>56=CDC<SOH>10=123<SOH>

6

8=imix1.0<SOH>34=1<SOH>35=A<SOH>52=20180514-22:37:45 234<SOH>49=FRONT_SHCH<SOH>56=CDC<SOH>10=123<SOH>

7

8=imix1.0<SOH>34=1<SOH>35=A<SOH>52=20180514-22:37:45 234<SOH>49=FRONT_SHCH<SOH>56=CDC<SOH>10=123<SOH>

8

8=imix1.0<SOH>34=1<SOH>35=A<SOH>52=20180514-22:37:45 234<SOH>49=FRONT_SHCH<SOH>56=CDC<SOH>10=123<SOH>

9

8=imix1.0<SOH>34=1<SOH>35=AQ<SOH>52=20180514-22:37:45 234<SOH>49=FRONT_SHCH<SOH>56=CDC<SOH>10=123<SOH>

10

8=imix1.0<SOH>34=1<SOH>35=

推荐:查看文件命令cat,more,less,tail,tac,nl,od---linux学习笔记

linux中查看文件的命令如下: cat: 由第一行开始显示档案内容 tac: 从最后一行开始显示,可以看出 tac 是 cat 的反向显示! nl: 显示的时候,随便输出行号!

AQ<SOH>52=20180514-22:37:45 234<SOH>49=FRONT_SHCH<SOH>56=CDC<SOH>10=123<SOH>

11

8=imix1.0<SOH>34=1<SOH>35=AP<SOH>52=20180514-22:37:45 234<SOH>49=FRONT_SHCH<SOH>56=CDC<SOH>10=123<SOH>

12

8=imix1.0<SOH>34=1<SOH>35=AR<SOH>52=20180514-22:37:45 234<SOH>49=FRONT_SHCH<SOH>56=CDC<SOH>10=123<SOH>

13

8=imix1.0<SOH>34=1<SOH>35=AE<SOH>52=20180514-22:37:45 234<SOH>49=FRONT_SHCH<SOH>56=CDC<SOH>10=123<SOH>

14

8=imix1.0<SOH>34=1<SOH>35=AE<SOH>52=20180514-22:37:45 234<SOH>49=FRONT_SHCH<SOH>56=CDC<SOH>10=123<SOH>

15

8=imix1.0<SOH>34=1<SOH>35=A<SOH>52=20180514-22:37:45 234<SOH>49=FRONT_SHCH<SOH>56=CDC<SOH>10=123<SOH>

16

8=imix1.0<SOH>34=1<SOH>35=AE<SOH>52=20180514-22:37:45 234<SOH>49=FRONT_SHCH<SOH>56=CDC<SOH>10=123<SOH>

17

8=imix1.0<SOH>34=1<SOH>35=A<SOH>52=20180514-22:37:45 234<SOH>49=FRONT_SHCH<SOH>56=CDC<SOH>10=123<SOH>

18

8=imix1.0<SOH>34=1<SOH>35=AE<SOH>52=20180514-22:37:45 234<SOH>49=FRONT_SHCH<SOH>56=CDC<SOH>10=123<SOH>

19

8=imix1.0<SOH>34=1<SOH>35=AE<SOH>52=20180514-22:37:45 234<SOH>49=FRONT_SHCH<SOH>56=CDC<SOH>10=123<SOH>

20

8=imix1.0<SOH>34=1<SOH>35=A<SOH>52=20180514-22:37:45 234<SOH>49=FRONT_SHCH<SOH>56=CDC<SOH>10=123<SOH>

21

8=imix1.0<SOH>34=1<SOH>35=A<SOH>52=20180514-22:37:45 234<SOH>49=FRONT_SHCH<SOH>56=CDC<SOH>10=123<SOH>

22

8=imix1.0<SOH>34=1<SOH>35=AR<SOH>52=20180514-22:37:45 234<SOH>49=FRONT_SHCH<SOH>56=CDC<SOH>10=123<SOH>

23

8=imix1.0<SOH>34=1<SOH>35=AE<SOH>52=20180514-22:37:45 234<SOH>49=FRONT_SHCH<SOH>56=CDC<SOH>10=123<SOH>[root@localhost example]#

从查询出结果看出,没有达到我们的要求:通过man grep查看参数到-v,相当于取反 [root@localhost example]# man grep

-v, --invert-match

Invert the sense of matching, to select non-matching lines.

(-v is specified by POSIX.) [root@localhost example]# cat -n 20180514.txt |grep '35=A'|grep -v '35=A[A-Z]'

1

8=imix1.0<SOH>34=1<SOH>35=A<SOH>52=20180514-22:37:45 234<SOH>49=FRONT_SHCH<SOH>56=CDC<SOH>10=123<SOH>

3

8=imix1.0<SOH>34=1<SOH>35=A<SOH>52=20180514-22:37:45 234<SOH>49=FRONT_SHCH<SOH>56=CDC<SOH>10=123<SOH>

4

8=imix1.0<SOH>34=1<SOH>35=A<SOH>52=20180514-22:37:45 234<SOH>49=FRONT_SHCH<SOH>56=CDC<SOH>10=123<SOH>

5

8=imix1.0<SOH>34=1<SOH>35=A<SOH>52=20180514-22:37:45 234<SOH>49=FRONT_SHCH<SOH>56=CDC<SOH>10=123<SOH>

6

8=imix1.0<SOH>34=1<SOH>35=A<SOH>52=20180514-22:37:45 234<SOH>49=FRONT_SHCH<SOH>56=CDC<SOH>10=123<SOH>

7

8=imix1.0<SOH>34=1<SOH>35=A<SOH>52=20180514-22:37:45 234<SOH>49=FRONT_SHCH<SOH>56=CDC<SOH>10=123<SOH>

8

8=imix1.0<SOH>34=1<SOH>35=A<SOH>52=20180514-22:37:45 234<SOH>49=FRONT_SHCH<SOH>56=CDC<SOH>10=123<SOH>

15

8=imix1.0<SOH>34=1<SOH>35=A<SOH>52=20180514-22:37:45 234<SOH>49=FRONT_SHCH<SOH>56=CDC<SOH>10=123<SOH>

17

8=imix1.0<SOH>34=1<SOH>35=A<SOH>52=20180514-22:37:45 234<SOH>49=FRONT_SHCH<SOH>56=CDC<SOH>10=123<SOH>

20

8=imix1.0<SOH>34=1<SOH>35=A<SOH>52=20180514-22:37:45 234<SOH>49=FRONT_SHCH<SOH>56=CDC<SOH>10=123<SOH>

21

8=imix1.0<SOH>34=1<SOH>35=A<SOH>52=20180514-22:37:45 234<SOH>49=FRONT_SHCH<SOH>56=CDC<SOH>10=123<SOH>[root@localhost example]#

达到我们的要求了。 查询从第三行之后的3行 [root@localhost example]# more +3 20180514.txt|head -38=imix1.0<SOH>34=1<SOH>35=A<SOH>52=20180514-22:37:45 234<SOH>49=FRONT_SHCH<SOH>56=CDC<SOH>10=123<SOH>8=imix1.0<SOH>34=1<SOH>35=A<SOH>52=20180514-22:37:45 234<SOH>49=FRONT_SHCH<SOH>56=CDC<SOH>10=123<SOH>8=imix1.0<SOH>34=1<SOH>35=A<SOH>52=20180514-22:37:45 234<SOH>49=FRONT_SHCH<SOH>56=CDC<SOH>10=123<SOH>[root@localhost example]#

推荐:linux grep命令

1.作用 Linux系统中grep命令是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹 配的行打印出来。grep全称是Global Regular Expression Print,表示

素材: [root@localhost example]# cat -n 20180514.txt 1 8=imix1.0<SOH>34=1<SOH>35=A<SOH>52=20180514-22:37:45 234<SOH>49=FRONT_SHCH<SOH>56=CDC<SOH>10=123<SOH> 2 3 8=imix1.0<SOH>34=1<

相关阅读排行


相关内容推荐

最新文章

×

×

请激活账号

为了能正常使用评论、编辑功能及以后陆续为用户提供的其他产品,请激活账号。

您的注册邮箱: 修改

重新发送激活邮件 进入我的邮箱

如果您没有收到激活邮件,请注意检查垃圾箱。