루프가 필요없는 솔루션이 있으므로 OP가 원하는 것을 제공합니다. tail -1
없이 비교
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")
는 너무 많은 라인 파일 당을 제공하지만, 위의 작품 증명한다.
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 –
유감스럽게도 전체 파일을 검색하고 마지막 결과 만 반환하면 대용량 파일이나 복잡한 패턴 검색에 효율적이지 않습니까? 당신의 for 루프에서 다음과 같은 것은 어떨까요? 'tac file | grep -m1 -oP '(? <=tag>). * (?=) '| head -n 1 ' 또는 심지어 grep -m1 -oP (? <=tag>)'(tac 파일) '<< (tac 파일) – kisna