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

阅读更多
素材:
[root@localhost example]# cat -n 20180514.txt
1 8=imix1.034=135=A52=20180514-22:37:45 23449=FRONT_SHCH56=CDC10=123
2
3 8=imix1.034=135=A52=20180514-22:37:45 23449=FRONT_SHCH56=CDC10=123
4 8=imix1.034=135=A52=20180514-22:37:45 23449=FRONT_SHCH56=CDC10=123
5 8=imix1.034=135=A52=20180514-22:37:45 23449=FRONT_SHCH56=CDC10=123
6 8=imix1.034=135=A52=20180514-22:37:45 23449=FRONT_SHCH56=CDC10=123
7 8=imix1.034=135=A52=20180514-22:37:45 23449=FRONT_SHCH56=CDC10=123
8 8=imix1.034=135=A52=20180514-22:37:45 23449=FRONT_SHCH56=CDC10=123
9 8=imix1.034=135=AQ52=20180514-22:37:45 23449=FRONT_SHCH56=CDC10=123
10 8=imix1.034=135=AQ52=20180514-22:37:45 23449=FRONT_SHCH56=CDC10=123
11 8=imix1.034=135=AP52=20180514-22:37:45 23449=FRONT_SHCH56=CDC10=123
12 8=imix1.034=135=AR52=20180514-22:37:45 23449=FRONT_SHCH56=CDC10=123
13 8=imix1.034=135=AE52=20180514-22:37:45 23449=FRONT_SHCH56=CDC10=123
14 8=imix1.034=135=AE52=20180514-22:37:45 23449=FRONT_SHCH56=CDC10=123
15 8=imix1.034=135=A52=20180514-22:37:45 23449=FRONT_SHCH56=CDC10=123
16 8=imix1.034=135=AE52=20180514-22:37:45 23449=FRONT_SHCH56=CDC10=123
17 8=imix1.034=135=A52=20180514-22:37:45 23449=FRONT_SHCH56=CDC10=123
18 8=imix1.034=135=AE52=20180514-22:37:45 23449=FRONT_SHCH56=CDC10=123
19 8=imix1.034=135=AE52=20180514-22:37:45 23449=FRONT_SHCH56=CDC10=123
20 8=imix1.034=135=A52=20180514-22:37:45 23449=FRONT_SHCH56=CDC10=123
21 8=imix1.034=135=A52=20180514-22:37:45 23449=FRONT_SHCH56=CDC10=123
22 8=imix1.034=135=AR52=20180514-22:37:45 23449=FRONT_SHCH56=CDC10=123
23 8=imix1.034=135=AE52=20180514-22:37:45 23449=FRONT_SHCH56=CDC10=123

 1、搜索出35=A的行

[root@localhost example]# cat -n 20180514.txt |grep '35=A'
     1  8=imix1.034=135=A52=20180514-22:37:45 23449=FRONT_SHCH56=CDC10=123
     3  8=imix1.034=135=A52=20180514-22:37:45 23449=FRONT_SHCH56=CDC10=123
     4  8=imix1.034=135=A52=20180514-22:37:45 23449=FRONT_SHCH56=CDC10=123
     5  8=imix1.034=135=A52=20180514-22:37:45 23449=FRONT_SHCH56=CDC10=123
     6  8=imix1.034=135=A52=20180514-22:37:45 23449=FRONT_SHCH56=CDC10=123
     7  8=imix1.034=135=A52=20180514-22:37:45 23449=FRONT_SHCH56=CDC10=123
     8  8=imix1.034=135=A52=20180514-22:37:45 23449=FRONT_SHCH56=CDC10=123
     9  8=imix1.034=135=AQ52=20180514-22:37:45 23449=FRONT_SHCH56=CDC10=123
    10  8=imix1.034=135=AQ52=20180514-22:37:45 23449=FRONT_SHCH56=CDC10=123
    11  8=imix1.034=135=AP52=20180514-22:37:45 23449=FRONT_SHCH56=CDC10=123
    12  8=imix1.034=135=AR52=20180514-22:37:45 23449=FRONT_SHCH56=CDC10=123
    13  8=imix1.034=135=AE52=20180514-22:37:45 23449=FRONT_SHCH56=CDC10=123
    14  8=imix1.034=135=AE52=20180514-22:37:45 23449=FRONT_SHCH56=CDC10=123
    15  8=imix1.034=135=A52=20180514-22:37:45 23449=FRONT_SHCH56=CDC10=123
    16  8=imix1.034=135=AE52=20180514-22:37:45 23449=FRONT_SHCH56=CDC10=123
    17  8=imix1.034=135=A52=20180514-22:37:45 23449=FRONT_SHCH56=CDC10=123
    18  8=imix1.034=135=AE52=20180514-22:37:45 23449=FRONT_SHCH56=CDC10=123
    19  8=imix1.034=135=AE52=20180514-22:37:45 23449=FRONT_SHCH56=CDC10=123
    20  8=imix1.034=135=A52=20180514-22:37:45 23449=FRONT_SHCH56=CDC10=123
    21  8=imix1.034=135=A52=20180514-22:37:45 23449=FRONT_SHCH56=CDC10=123
    22  8=imix1.034=135=AR52=20180514-22:37:45 23449=FRONT_SHCH56=CDC10=123
    23  8=imix1.034=135=AE52=20180514-22:37:45 23449=FRONT_SHCH56=CDC10=123
[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.034=135=A52=20180514-22:37:45 23449=FRONT_SHCH56=CDC10=123
     3  8=imix1.034=135=A52=20180514-22:37:45 23449=FRONT_SHCH56=CDC10=123
     4  8=imix1.034=135=A52=20180514-22:37:45 23449=FRONT_SHCH56=CDC10=123
     5  8=imix1.034=135=A52=20180514-22:37:45 23449=FRONT_SHCH56=CDC10=123
     6  8=imix1.034=135=A52=20180514-22:37:45 23449=FRONT_SHCH56=CDC10=123
     7  8=imix1.034=135=A52=20180514-22:37:45 23449=FRONT_SHCH56=CDC10=123
     8  8=imix1.034=135=A52=20180514-22:37:45 23449=FRONT_SHCH56=CDC10=123
    15  8=imix1.034=135=A52=20180514-22:37:45 23449=FRONT_SHCH56=CDC10=123
    17  8=imix1.034=135=A52=20180514-22:37:45 23449=FRONT_SHCH56=CDC10=123
    20  8=imix1.034=135=A52=20180514-22:37:45 23449=FRONT_SHCH56=CDC10=123
    21  8=imix1.034=135=A52=20180514-22:37:45 23449=FRONT_SHCH56=CDC10=123
[root@localhost example]#

 达到我们的要求了。

查询从第三行之后的3行

[root@localhost example]# more +3 20180514.txt|head -3
8=imix1.034=135=A52=20180514-22:37:45 23449=FRONT_SHCH56=CDC10=123
8=imix1.034=135=A52=20180514-22:37:45 23449=FRONT_SHCH56=CDC10=123
8=imix1.034=135=A52=20180514-22:37:45 23449=FRONT_SHCH56=CDC10=123
[root@localhost example]#

 

 

 

 

 

你可能感兴趣的:(Linux,cat,grep)