当使用Grep命令在一组文件中查找搜索字符串时,是否可以将结果转储为文本文件? 还有一个Grep命令的开关,它提供更清晰的结果以提高可读性,,比如每个条目之间的换行符? 也许有一个Grep脚本可以输出更清晰的结果
谢谢
解决方案 div> grep -n您的搜索字符串*>输出文件-n 会打印行号和> 会将grep-results重定向到输出文件。 如果您想清理结果,您可以使用管道 | 来过滤它们,例如: grep -ntest* | grep -vmytest>输出文件 将匹配所有具有字符串test的行,除了匹配字符串mytest的行(即交换机 -v ) - 并将结果重定向到输出文件。 一些很好的grep-tips可以在上找到这篇文章
When using the Grep command to find a search string in a set of files, is there a way to dump the results to a text file? Also is there a switch for the Grep command that provides cleaner results for better readability, such as a line feed between each entry? Perhaps there is a Grep script that outputs cleaner results
Thanks
解决方案 grep -n "YOUR SEARCH STRING" * > output-fileThe -n will print the line number and the > will redirect grep-results to the output-file. If you want to "clean" the results you can filter them using pipe | for example: grep -n "test" * | grep -v "mytest" > output-file will match all the lines that have the string "test" except the lines that match the string "mytest" (that's the switch -v) - and will redirect the result to an output file. A few good grep-tips can be found on this post
更多推荐
使用Linux Grep命令
发布评论