有沒有需要循環的解決方案,這給出了OP所需要的。
find . -type f -exec sh -c "fgrep print {} /dev/null |tail -1" \;
./tway.pl:print map(lambda x : x[1], filter(lambda x : x[0].startswith('volume'), globals().items()))
./txml.py: print("%s does not exist: %s\n" % (host, error))
./utils.py:print combine_dicts(a, b, operator.mul)
./xml_example.py:print ET.tostring(root, method="text")
沒有tail -1
相比給人太多行每個文件,但證明上述作品。
find . -type f -exec sh -c "fgrep print {} /dev/null" \;
給出:
./tway.pl:print map(lambda x : x[1], filter(lambda x : x[0].startswith('volume'), globals().items()))
./txml.py: print("%s resolved to --> %s\n" % (host, ip))
./txml.py: print("%s does not exist: %s\n" % (host, error))
./utils.py:print "a", a
./utils.py:print "b", b
./utils.py:print combine_dicts(a, b, operator.mul)
./xml_example.py: print ">>"
./xml_example.py: print ET.tostring(e, method="text")
./xml_example.py: print "<<"
./xml_example.py:print ET.tostring(root, method="text")
編輯 - 刪除的/ dev/null的,如果你不想要的文件名包含在輸出。
很好用!謝謝! :d – 2013-02-15 12:48:15
不幸的是,這不會是有效的大型文件或複雜的模式搜索,如果你正在尋找整個文件並返回剛剛過去的結果?如何像下面這樣,在你的for循環: 'TAC文件| grep的-M1 -OP「(?<=tag>)。*(?=)'| head -n 1' 或甚至 'grep -m1 -oP'(?<=tag>)。*(?=)'<<(tac文件)' – kisna 2015-08-02 14:43:10