首页 > 其他分享 >grep - useful options

grep - useful options

时间:2023-08-04 14:57:09浏览次数:36  
标签:abc grep option sh abc3 useful options match

The “ -c ” option counts the number of occurrences of a string: even though ABC4.sh has no matches, it still counts them and returns zero:
grep –c abc *sh
The output of the preceding command is here:
ABC4.sh:0
abc3.sh:3


The “ -e ” option lets you match patterns that would otherwise cause syntax problems (the “–” character normally is interpreted as an argument for grep ):
grep –e "-abc" *sh
abc3.sh:ends with -abc
The “ -e ” option also lets you match multiple patterns:
grep –e "-abc" -e "comment" *sh
ABC4.sh:# ABC in a comment
abc3.sh:ends with -abc

 

Use the “ -iv ” options to display the lines that do not contain a specified string using a case insensitive match:
grep –iv abc *sh
ABC4.sh:
abc3.sh:this line won't match


The “ -l ” option is to list only the filenames that contain a successful match (note this matches contents of files, not the filenames). The Word document matches because the actual text is still visible to grep , it is just surrounded by proprietary formatting gibberish. You can do similar things with other formats that contain text, such as XML, HTML, CSV, and so forth:
grep -l abc *

The “ -l ” option is to list only the filenames that contain a successful match:
grep –l abc *sh
Use the “ -il ” options to display the filenames that contain a specified string using a case insensitive match:
grep –il abc *doc
The preceding command is very useful when you want to check for the occurrence of a string in Word documents.

 

The “ -n ” option specifies line numbers of any matching file:
grep –n abc *sh
abc3.sh:1:abc at start
abc3.sh:2:ends with -abc
abc3.sh:3:the abc is in the middle


The “ -h ” option suppresses the display of the filename for a successful match:
grep –h abc *sh
abc at start
ends with -abc
the abc is in the middle

标签:abc,grep,option,sh,abc3,useful,options,match
From: https://www.cnblogs.com/zhangzhihui/p/17605914.html

相关文章

  • grep - Meta Characters
    MetaCharactersandthegrepCommandThefundamentalbuildingblocksaretheregularexpressionsthatmatchasinglecharacter.Mostcharacters,includingalllettersanddigits,areregularexpressionsthatmatchthemselves.Anymeta-characterwithspeci......
  • android开发Android studio卡顿配置studio64.exe.vmoptions文件的解决方法
    备份一下studio64.exe.vmoptions写法:-Xms2g-Xmx16g-XX:ReservedCodeCacheSize=2g-XX:+IgnoreUnrecognizedVMOptions-XX:+UseG1GC-XX:SoftRefLRUPolicyMSPerMB=100-XX:CICompilerCount=2-XX:+HeapDumpOnOutOfMemoryError-XX:-OmitStackTraceInFastThrow-da-Djna.nosys=t......
  • grep 中的正则流派
    简单记录下,使用grep时所用的正则的问题。 简单来说,正则分为两个流派POSIX  和 PCRE。Linux上的工具的正则大多是基于POSIX(Unix通用规范)的,其中又分为BRE(基础版)和ERE(进阶版)grep,使用POSIX的基础版正则。。。 但(){} 都需要转义为\( \) \{ \}并......
  • egrep
    egrep在文件内查找指定的字符串补充说明egrep命令用于在文件内查找指定的字符串。egrep执行效果与grep-E相似,使用的语法及参数可参照grep指令,与grep的不同点在于解读字符串的方法。egrep是用extendedregularexpression语法来解读的,而grep则用basicregularexpression语法......
  • GO 编程模式:FUNCTIONAL OPTIONS
    在本篇文章中,我们来讨论一下FunctionalOptions这个编程模式。这是一个函数式编程的应用案例,编程技巧也很好,是目前在Go语言中最流行的一种编程模式。但是,在我们正式讨论这个模式之前,我们需要先来看看要解决什么样的问题。本文是全系列中第3/10篇:Go编程模式Go编程模式:切片,接口......
  • grep
    grep强大的文本搜索工具补充说明grep(globalsearchregularexpression(RE)andprintouttheline,全面搜索正则表达式并把行打印出来)是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹配的行打印出来。用于过滤/搜索的特定字符。可使用正则表达式能配合多种命令使......
  • grep
    1.获取文件中的关键字key:catfileName|grep"key"2.获取文件中的某个关键字key1,key2,key3:catfileName|grep-E"key1|key2|key3"3.获取文件中的多个关键字,同时满足:catfileName|grepkey1|grepkey2|grepkey34.忽略文件中的某个关键字,需要转义......
  • linux 中 grep命令精准匹配制表符
     001、[root@PC1test02]#lsa.txt[root@PC1test02]#cata.txt##测试数据321971225792194632197622553381184532197222609449473219872253144109......
  • pgrep
    pgrep根据用户给出的信息在当前运行进程中查找并列出符合条件的进程ID(PID)补充说明pgrep命令以名称为依据从运行进程队列中查找进程,并显示查找到的进程id。每一个进程ID以一个十进制数表示,通过一个分割字符串和下一个ID分开,默认的分割字符串是一个新行。对于每个属性选项,用户可......
  • Learn about some useful truck diagnostic scanner tools
    Haveyoueverexperiencedthefrustrationofunexpectedbreakdownswithyourtruck?Ormaybeyou’retiredofpayingexpensivediagnosticfeesatyourlocaldealership.Well,worrynomore!Thetruckdiagnosticscannertoolisheretomakeyourlifeeasier......