字符类和括号表达式的高级 Linux ‘Grep‘ 命令

字符类和括号表达式的高级 Linux ‘Grep’ 命令

您是否遇到过需要在文件中搜索字符串、单词或模式的情况?如果是,那么grep实用程序在这种情况下会派上用场。可以先直接猜想用什么参数

grep 是一个命令行实用程序,用于在纯文本数据中搜索匹配正则表达式的行。如果将分词的grep等克/重/ P然后的含义的grep被(全局搜索正则表达式和打印),该搜索模式从文件和打印屏幕即标准输出就行了。

在本文中,我将去上解释先进命令的grep的字符类在Linux和Unix类操作系统。

在这里,我认为tecmint.txt是基本文件,我们将在本文中借助grep命令搜索模式以进行解释。

  1. 搜索字母数字字符
    如果您在一个文件中有数千行并且想要搜索仅从A-Z, a-z& 0-9(字母数字字符)开始的行。

$ grep “1” tecmint.txt

  1. 搜索字母字符
    类似的选项,例如如果您想搜索仅从[A-Z & a-z]ie开始的行Alpha Characters。

$ grep “2” tecmint.txt

  1. 搜索空白字符
    另一个选项,比如如果你想搜索将从[Tab & Space]即空白字符开始的行。

$ grep “3” tecmint.txt

  1. 搜索数字字符
    grep 的 digit 选项对于搜索从 digit 开始的行也非常有用,[0-9]即Digit Characters。

$ grep “4” tecmint.txt

  1. 搜索小写字母
    grep 的另一个选择是搜索将从小写字母开始的行,即[a-z](小写字母)。

$ grep “5” tecmint.txt

  1. 搜索标点符号
    grep 的标点符号是搜索从[! ” # $ % & ’ ( ) * + , – . / : ; < = > ? @ [ \ ] ^ _ ` { | }~。]即标点符号。

$ grep “6” tecmint.txt

  1. 搜索图形字符
    grep 还用于搜索将从称为图形字符的字母数字和标点字符开始的行。

$ grep “7” tecmint.txt

  1. 搜索可打印字符
    与Graphical Characters类似,grep 可用于搜索将从字母数字、标点符号和空格字符开始的行。

$ grep “8” tecmint.txt

  1. 搜索空格字符
    grep 还具有搜索行的功能,该行将从[制表符、换行符、垂直制表符、换页符、回车符和空格] 开始,即空格字符。

$ grep “9” tecmint.txt

  1. 搜索大写字母
    在另一个grep的选项也可用于搜索线将从开始[A-Z]即大写字母。

$ grep “10” tecmint.txt

  1. 搜索十六进制数字
    grep 搜索将从[0-9, A-F and a-f]ie Hexadecimal Digits开始的行。

$ grep “11” tecmint.txt

我已经解释了grep的高级功能,它是在文件中搜索模式的非常强大的工具。


  1. [:alnum:] ↩︎

  2. [:alpha:] ↩︎

  3. [:blank:] ↩︎

  4. [:digit:] ↩︎

  5. [:lower:] ↩︎

  6. [:punct:] ↩︎

  7. [:graph:] ↩︎

  8. [:print:] ↩︎

  9. [:space:] ↩︎

  10. [:upper:] ↩︎

  11. [:xdigit:] ↩︎

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
linux-command Linux命令大全搜索工具,内容包含Linux命令手册、详解、学习、搜集。    Linux命令 这里存放Linux 命令大全并不全,你可以通过linux-command来搜索,它是把 command 目录里面搜集的命令,生成了静态HTML并提供预览以及索引搜索。 文件传输 bye、ftp、ftpcount、ftpshut、ftpwho、ncftp、tftp、uucico、uucp、uupick、uuto 备份压缩 ar、bunzip2、bzip2、bzip2recover、compress、cpio、dump、gunzip、gzexe、gzip、lha、restore、tar、unarj、unzip、zip、zipinfo 文件管理 diff、diffstat、file、find、gitgitview、ln、locate、lsattr、mattrib、mc、mcopy、mdel、mdir、mktemp、mmove、mread、mren、mshowfat、mtools、mtoolstest、mv、od、paste、patch、rcp、rhmask、rm、slocate、split、tee、tmpwatch、touch、umask、whereis、which、cat、chattr、chgrp、chmod、chown、cksum、cmp、cp、cut、indent 磁盘管理 cd、df、dirs、du、edquota、eject、lndir、ls、mcd、mdeltree、mdu、mkdir、mlabel、mmd、mmount、mrd、mzip、pwd、quota、quotacheck、quotaoff、quotaon、repquota、rmdir、rmt、stat、tree、umount 磁盘维护 badblocks、cfdisk、dd、e2fsck、ext2ed、fdisk、fsck.ext2、fsck、fsck.minix、fsconf、hdparm、losetup、mbadblocks、mformat、mkbootdisk、mkdosfs、mke2fs、mkfs.ext2、mkfs、mkfs.minix、mkfs.msdos、mkinitrd、mkisofs、mkswap、mpartition、sfdisk、swapoff、swapon、symlinks、sync 系统设置 alias、apmd、aumix、bind、chkconfig、chroot、clock、crontab、declare、depmod、dircolors、dmesg、enable、eval、export、fbset、grpconv、grpunconv、hwclock、insmod、kbdconfig、lilo、liloconfig、lsmod、minfo、mkkickstart、modinfo、modprobe、mouseconfig、ntsysv、passwd、pwconv、pwunconv、rdate、resize、rmmod、rpm、set、setconsole、setenv、setup、sndconfig、SVGAText Mode、timeconfig、ulimit、unalias、unset 系统管理 adduser、chfn、chsh、date、exit、finger、free、fwhois、gitps、groupdel、groupmod、halt、id、kill、last、lastb、login、logname、logout、logrotate、newgrp、nice、procinfo、ps、pstree、reboot、renice、rlogin、rsh、rwho、screen、shutdown、sliplogin、su、sudo、suspend、swatch、tload、top、uname、useradd、userconf、userdel、usermod、vlock、w、who、whoami、whois 文档编辑 col、colrm、comm、csplit、ed、egrep、ex、fgrep、fmt、fold、grep、ispell、jed、joe、join、look、mtype、pico、rgrep、sed、sort、spell、tr、uniq、wc 网络通讯 dip、getty、mingetty、ppp-off、smbd(samba daemon)、telnet、uulog、uustat、uux、cu、dnsconf、efax、httpd
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值