如何将管道的grep结果写入文件

时间:2017-02-08 12:48:42

标签: linux bash grep

我想在目录中保存一些简单的图像信息(如下图所示): enter image description here

但是如何将匹配的部分写入文件? 我试过追加>> img_info.txt但它写了整个输出而不是选择性。

1 个答案:

答案 0 :(得分:1)

按照Can grep show only words that match search pattern?中的说明尝试grep的选项-o

引用另一个答案:

-o, --only-matching
    Print  only  the matched (non-empty) parts of a matching line,
    with each such part on a separate output line.

除此之外,grep可能不是搜索和提取字符串的最佳工具。这相当于sedawk

的工作
相关问题