![리눅스에서 문자열의 첫 번째 발생부터 시작하여 n 줄을 찾는 방법은 무엇입니까? [복사]](https://linux55.com/image/222260/%EB%A6%AC%EB%88%85%EC%8A%A4%EC%97%90%EC%84%9C%20%EB%AC%B8%EC%9E%90%EC%97%B4%EC%9D%98%20%EC%B2%AB%20%EB%B2%88%EC%A7%B8%20%EB%B0%9C%EC%83%9D%EB%B6%80%ED%84%B0%20%EC%8B%9C%EC%9E%91%ED%95%98%EC%97%AC%20n%20%EC%A4%84%EC%9D%84%20%EC%B0%BE%EB%8A%94%20%EB%B0%A9%EB%B2%95%EC%9D%80%20%EB%AC%B4%EC%97%87%EC%9E%85%EB%8B%88%EA%B9%8C%3F%20%5B%EB%B3%B5%EC%82%AC%5D.png)
개발자와 로그를 공유해야 합니다. 그들은 계속해서 더 많은 로그를 요구했습니다. 그래서 Linux에서 문자열이 처음 발생한 후 1000줄 정도를 grep하는 방법이 있는지 궁금합니다.
답변1
다음 옵션을 원할 수 있습니다 -A
. 매뉴얼 페이지에서:
컨텍스트 라인 제어
-A NUM, --after-context=NUM Print NUM lines of trailing context after matching lines. Places a line containing a group separator (--) between contiguous groups of matches. With the -o or --only-matching option, this has no effect and a warning is given. -B NUM, --before-context=NUM Print NUM lines of leading context before matching lines. Places a line containing a group separator (--) between contiguous groups of matches. With the -o or --only-matching option, this has no effect and a warning is given. -C NUM, -NUM, --context=NUM Print NUM lines of output context. Places a line containing a group separator (--) between contiguous groups of matches. With the -o or --only-matching option, this has no effect and a warning is given.