Show lines before and after If you need a little more context to the grep output, you can show one line before and after your specified search string with the -c switch: $ grep -c 1 string filename Specify the number of lines you wish to show – we did only 1 line in this example...
Can you give me a simple examples of the grep command? How do I use grep command on Linux, Apple OS X, and Unix-like operating systems? The grep command is used to search text or searches the given file for lines containing a match to the given strings or words. By default, grep d...
基本用法:grep[-acinv] [--color=auto] [-A n] [-B n] '搜寻字符串' 文件名 参数说明: -a:将二进制文档以文本方式处理 -c:显示匹配次数 -i:忽略大小写差异 -n:在行首显示行号 -A:After的意思,显示匹配字符串后n行的数据 -B:before的意思,显示匹配字符串前n行的数据 -v ...
-A<显示行数>,--after-context=<显示行数>:除了显示符合字符的那一行之外,并显示该行之后的内容。-b,--byte-offset:在显示符合字符的那一行之前,标示出该行第一个字符的编号。-B<显示行数>,--before-context=<显示行数>:除了显示符合字符的那一行之外,并显示该行之前的内容。-c,--count:计算符合字符的...
Print Number of Lines Before and After String 5. Prints Number of Lines Around Match The grep’s-Coption is similar, but instead of printing the lines that come either before or after the string, it prints the lines in either direction: ...
Stop reading a file after NUM matching lines. If the input is standard input from a regular file, and NUM matching lines are output, grep ensures that the standard input is positioned to just after the last matching line before exiting, regardless of the presence of trailing context lines. ...
grep -b10 "bug" info.log # 查看"bug"字符前的10行,b->before。grep -c10 "bug" info.log...
-c, --count print only a count of matching lines per FILE -T, --initial-tab make tabs line up (if needed) -Z, --null print 0 byte after FILE name Context control: -B, --before-context=NUM print NUM lines of leading context ...
-c, --count print only a count of matching lines per FILE -T, --initial-tab make tabs line up (if needed) -Z, --null print 0 byte after FILE name Context control: -B, --before-context=NUM print NUM lines of leading context ...
--version display version information and exit--help display this help text and exitOutputcontrol: // 输出控制-m,--max-count=NUM stop after NUM matches-b,--byte-offset print the byte offset with output lines-n,--line-number print line number with output lines--line-buffered flush output ...