仅从grep获取最后一个匹配项并转储到文件中

我有以下命令:
grep -Rl -e '^\s\s"status" : "failed"' -e '^\s\s"status" : "broken"' | xargs grep '\.png",$'

命令返回以下内容:

16c739694364ec84.json:        "source" : "a77b00b33055098d.png",16c739694364ec84.json:        "source" : "282eb13faf790c0b.png",26d937b0dcfc748a.json:        "source" : "8af0cf9b9a3dad20.png",26d937b0dcfc748a.json:        "source" : "d9a2b6cefa94f257.png",3ac10f00de722ec8.json:            "source" : "94f1916860cb1610.png",3ac10f00de722ec8.json:          "source" : "386f5bbd0d5831d0.png",3ac10f00de722ec8.json:        "source" : "1aba5c856edf35c3.png",3ac10f00de722ec8.json:        "source" : "feab31f43a51a038.png",62340894812a7106.json:        "source" : "768cf3927206f24a.png",62340894812a7106.json:        "source" : "94e0308263a3c1d.png",72eacc757480542f.json:        "source" : "ef3bae66ed0ba8ba.png",

如何从返回的每个* .json中仅获取最后一个* .png并将其添加到文件中?

预期的文件内容:

282eb13faf790c0b.png
d9a2b6cefa94f257.png
feab31f43a51a038.png
94e0308263a3c1d.png
ef3bae66ed0ba8ba.png

注意*:我打算将输出文件用作rsync命令的排除列表。

fankangkangkang 回答:仅从grep获取最后一个匹配项并转储到文件中

添加到命令 cut tr

grep -Rl -e '^\s\s"status" : "failed"' \
    -e '^\s\s"status" : "broken"' \
    | xargs grep '\.png",$' \
    | cut -d':' -f3 \          # split result for 3 columns and get third one
    | tr -d ' ",' \            # trim space and '"' ',' chars
    | > rsync-excludes         # save results into file
本文链接:https://www.f2er.com/3165721.html

大家都在问