首页 > 系统相关 >linux 中grep命令限制数字匹配的次数

linux 中grep命令限制数字匹配的次数

时间:2023-02-07 09:45:27浏览次数:40  
标签:052532.1 匹配 NC AGA TRNAS tRNAscan linux grep SE

 

001、

[root@PC1 test]# ls
a.txt
[root@PC1 test]# cat a.txt                         ## 测试数据
NC_052532.1     tRNAscan-SE     TRNAD-GUC_1
NC_052532.1     tRNAscan-SE     TRNAD-GUC_229
NC_052532.1     tRNAscan-SE     TRNAS-AGA_1
NC_052532.1     tRNAscan-SE     TRNAS-AGA_27
NC_052532.1     tRNAscan-SE     TRNAS-AGA_3
NC_052532.1     tRNAscan-SE     TRNAS-AGA_45
NC_052532.1     tRNAscan-SE     TRNAI-AAU_12
NC_052532.1     tRNAscan-SE     TRNAD-GUC_3
NC_052532.1     tRNAscan-SE     TRNAD-GUC_4
NC_052532.1     tRNAscan-SE     TRNAI-AAU_2
[root@PC1 test]# grep "_[0-9]$" a.txt             ## 匹配末尾为_数字的数据,进匹配了一次
NC_052532.1     tRNAscan-SE     TRNAD-GUC_1
NC_052532.1     tRNAscan-SE     TRNAS-AGA_1
NC_052532.1     tRNAscan-SE     TRNAS-AGA_3
NC_052532.1     tRNAscan-SE     TRNAD-GUC_3
NC_052532.1     tRNAscan-SE     TRNAD-GUC_4
NC_052532.1     tRNAscan-SE     TRNAI-AAU_2

 

 

002、

[root@PC1 test]# ls
a.txt
[root@PC1 test]# cat a.txt
NC_052532.1     tRNAscan-SE     TRNAD-GUC_1
NC_052532.1     tRNAscan-SE     TRNAD-GUC_229
NC_052532.1     tRNAscan-SE     TRNAS-AGA_1
NC_052532.1     tRNAscan-SE     TRNAS-AGA_27
NC_052532.1     tRNAscan-SE     TRNAS-AGA_3
NC_052532.1     tRNAscan-SE     TRNAS-AGA_45
NC_052532.1     tRNAscan-SE     TRNAI-AAU_12
NC_052532.1     tRNAscan-SE     TRNAD-GUC_3
NC_052532.1     tRNAscan-SE     TRNAD-GUC_4
NC_052532.1     tRNAscan-SE     TRNAI-AAU_2
[root@PC1 test]# grep "_[0-9]\+" a.txt              ## 匹配末尾_加数字一次以上
NC_052532.1     tRNAscan-SE     TRNAD-GUC_1
NC_052532.1     tRNAscan-SE     TRNAD-GUC_229
NC_052532.1     tRNAscan-SE     TRNAS-AGA_1
NC_052532.1     tRNAscan-SE     TRNAS-AGA_27
NC_052532.1     tRNAscan-SE     TRNAS-AGA_3
NC_052532.1     tRNAscan-SE     TRNAS-AGA_45
NC_052532.1     tRNAscan-SE     TRNAI-AAU_12
NC_052532.1     tRNAscan-SE     TRNAD-GUC_3
NC_052532.1     tRNAscan-SE     TRNAD-GUC_4
NC_052532.1     tRNAscan-SE     TRNAI-AAU_2

 

 

003、

[root@PC1 test]# cat a.txt
NC_052532.1     tRNAscan-SE     TRNAD-GUC_1
NC_052532.1     tRNAscan-SE     TRNAD-GUC_229
NC_052532.1     tRNAscan-SE     TRNAS-AGA_1
NC_052532.1     tRNAscan-SE     TRNAS-AGA_27
NC_052532.1     tRNAscan-SE     TRNAS-AGA_3
NC_052532.1     tRNAscan-SE     TRNAS-AGA_45
NC_052532.1     tRNAscan-SE     TRNAI-AAU_12
NC_052532.1     tRNAscan-SE     TRNAD-GUC_3
NC_052532.1     tRNAscan-SE     TRNAD-GUC_4
NC_052532.1     tRNAscan-SE     TRNAI-AAU_2
[root@PC1 test]# grep "_[0-9]\{2\}$" a.txt      ## 指定匹配次数为2次
NC_052532.1     tRNAscan-SE     TRNAS-AGA_27
NC_052532.1     tRNAscan-SE     TRNAS-AGA_45
NC_052532.1     tRNAscan-SE     TRNAI-AAU_12
[root@PC1 test]# grep "_[0-9]\{3\}$" a.txt      ## 指定匹配次数为3次
NC_052532.1     tRNAscan-SE     TRNAD-GUC_229

 

 

004、

[root@PC1 test]# ls
a.txt
[root@PC1 test]# cat a.txt
NC_052532.1     tRNAscan-SE     TRNAD-GUC_1
NC_052532.1     tRNAscan-SE     TRNAD-GUC_229
NC_052532.1     tRNAscan-SE     TRNAS-AGA_1
NC_052532.1     tRNAscan-SE     TRNAS-AGA_27
NC_052532.1     tRNAscan-SE     TRNAS-AGA_3
NC_052532.1     tRNAscan-SE     TRNAS-AGA_45
NC_052532.1     tRNAscan-SE     TRNAI-AAU_12
NC_052532.1     tRNAscan-SE     TRNAD-GUC_3
NC_052532.1     tRNAscan-SE     TRNAD-GUC_4
NC_052532.1     tRNAscan-SE     TRNAI-AAU_2
[root@PC1 test]# grep "_[0-9]\{2\}$" a.txt        ## 匹配两次
NC_052532.1     tRNAscan-SE     TRNAS-AGA_27
NC_052532.1     tRNAscan-SE     TRNAS-AGA_45
NC_052532.1     tRNAscan-SE     TRNAI-AAU_12
[root@PC1 test]# grep "_[0-9]\{2,\}$" a.txt       ## 匹配数字至少两次
NC_052532.1     tRNAscan-SE     TRNAD-GUC_229
NC_052532.1     tRNAscan-SE     TRNAS-AGA_27
NC_052532.1     tRNAscan-SE     TRNAS-AGA_45
NC_052532.1     tRNAscan-SE     TRNAI-AAU_12

 

005、

[root@PC1 test]# ls
a.txt
[root@PC1 test]# cat a.txt
NC_052532.1     tRNAscan-SE     TRNAD-GUC_1
NC_052532.1     tRNAscan-SE     TRNAD-GUC_229
NC_052532.1     tRNAscan-SE     TRNAS-AGA_1
NC_052532.1     tRNAscan-SE     TRNAS-AGA_27
NC_052532.1     tRNAscan-SE     TRNAS-AGA_3
NC_052532.1     tRNAscan-SE     TRNAS-AGA_45
NC_052532.1     tRNAscan-SE     TRNAI-AAU_12
NC_052532.1     tRNAscan-SE     TRNAD-GUC_3
NC_052532.1     tRNAscan-SE     TRNAD-GUC_4
NC_052532.1     tRNAscan-SE     TRNAI-AAU_2
[root@PC1 test]# grep "_[0-9]\{,2\}$" a.txt      ## 匹配至多为两次
NC_052532.1     tRNAscan-SE     TRNAD-GUC_1
NC_052532.1     tRNAscan-SE     TRNAS-AGA_1
NC_052532.1     tRNAscan-SE     TRNAS-AGA_27
NC_052532.1     tRNAscan-SE     TRNAS-AGA_3
NC_052532.1     tRNAscan-SE     TRNAS-AGA_45
NC_052532.1     tRNAscan-SE     TRNAI-AAU_12
NC_052532.1     tRNAscan-SE     TRNAD-GUC_3
NC_052532.1     tRNAscan-SE     TRNAD-GUC_4
NC_052532.1     tRNAscan-SE     TRNAI-AAU_2

 

 

006、

[root@PC1 test]# ls
a.txt
[root@PC1 test]# cat a.txt
NC_052532.1     tRNAscan-SE     TRNAD-GUC_1
NC_052532.1     tRNAscan-SE     TRNAD-GUC_229
NC_052532.1     tRNAscan-SE     TRNAS-AGA_1
NC_052532.1     tRNAscan-SE     TRNAS-AGA_27
NC_052532.1     tRNAscan-SE     TRNAS-AGA_3
NC_052532.1     tRNAscan-SE     TRNAS-AGA_453344
NC_052532.1     tRNAscan-SE     TRNAI-AAU_12
NC_052532.1     tRNAscan-SE     TRNAD-GUC_3
NC_052532.1     tRNAscan-SE     TRNAD-GUC_4325635
NC_052532.1     tRNAscan-SE     TRNAI-AAU_2
[root@PC1 test]# grep "_[0-9]\{2,5\}$" a.txt         ## 匹配至少为2次,至多为5次
NC_052532.1     tRNAscan-SE     TRNAD-GUC_229
NC_052532.1     tRNAscan-SE     TRNAS-AGA_27
NC_052532.1     tRNAscan-SE     TRNAI-AAU_12

 

标签:052532.1,匹配,NC,AGA,TRNAS,tRNAscan,linux,grep,SE
From: https://www.cnblogs.com/liujiaxin2018/p/17097352.html

相关文章

  • Linux上安装jdk及环境配置
    一.查看是否已安装jdk输入:java-version,查看当前是否有jdk版本如果有,且你想重装jdk则进行检测jdk的安装包:rpm-qa|grepjava然后一个个删除包:rpm-e--nodeps+包名......
  • 常见用法grep_tail_more
    grep用grep来搜索多个条件AND条件 使用-E'pattern1.*pattern2'实现AND操作。 grep-E'pattern1.*pattern2'filename grep-E'pattern1.*pattern2|pattern2......
  • Rocky Linux 防火墙开放端口号流程
    RockyLinux防火墙开放端口号流程1.添加需要开放的端口firewall-cmd--zone=public--add-port=9001/tcp--permanent#permanent代表永久添加2.重启防火墙firewa......
  • 2. Linux用户管理
    1.用户管理1.1用户信息相关文件​/etc/passwd​​:存储用户的基本信息​root:x:0:0:root:/root:/bin/bash​​用户名:密码占位符:UID:GID:描述:​用户名密码:都是​​x​​,......
  • Linux文件目录管理操作
    文件目录管理操作cd,ls1、查看文件内容​ cat/less/more/head/tail1)、cat[root@localhost~]#cat/etc/fstab查看操作系统版本[root@localhost~]#cat/e......
  • Linux下磁盘扩容
    我们使用虚拟机时,不时会遇到空间不够的问题。虽然虚拟机扩容比较方便,但扩容后并不能直接使用,仍然需要在系统中调整,在windows中可以使用diskgenius等工具快速完成这个步骤,......
  • root用户远程连接RocklyLinux9
    由于RocklyLinux9默认是拒绝Root用户22端口远程访问,所以需要进行调整1、登录服务器2、进入目录vi/etc/ssh/sshd_config3、修改PermitRootLoginprohibit-password为P......
  • linux平台makefile文件的编写基础篇
    目的:基本掌握了make的用法,能在Linux系统上编程。环境:Linux系统,或者有一台Linux服务器,通过终端连接。一句话:有Linux编译环境。准备:准备三个文件:fil......
  • 盘点Linux系统最常用的4个关机命令!
    在Linux系统中如果想要关机可以通过命令来完成,那么Linux系统中常用的关机命令有哪些?主要包括:shutdown、halt、reboot、init,接下来是详细的内容介绍。Linux系统中我......
  • 4款常用的Linux手机远程工具!
    作为一名专业的Linux运维工程师,当我们进行服务器维护时,通常都是采用远程连接的方式进行操作及控制;而在多数情况下,很多人都是通过电脑进行远程操作的,但某种情况下,可能身......