我想从文件中搜索以下段落,然后显示段落中的特定单词。 例如
"Documentation can be done using
MS excel and an eg. of such a file is sample.xls"
我想从文件example.log中搜索上面的段落,然后只想显示单词“sample.xls”
有可能???
答案 0 :(得分:0)
如果你的grep支持-P
,perl-regexp参数,那么你可以简单地使用下面的grep命令。
$ grep -ozP '(?:.+\n)*.*\bDocumentation can\b.*(?:\n.+)*' file | grep -o '[^ ]\+\.xls\b'
sample.xls
第一个grep用于获取特定段落,下一个grep用于从该段落中获取具有特定扩展名的文件。