원출처는
http://unix.stackexchange.com/questions/6979/grep-count-total-number-of-occurrences
파일안에 특정 스트링이 총 몇번 나오는지 세려고 -c옵션을 쓰면, 해당 스트링을 포함하는 라인수만 나온다. 예를 들어 라인은 하나인데(\n이 딱 하나 들어있는데) 스트링은 수천만자에 달하는 긴 스트링에 대해 grep -c string 하면 1만 나온다는 뜻.
-o 옵션과 wc 명령을 섞어 쓴다.
grep -o string filename | wc -l
-o
--only-matching
Print only the matched (non-empty) parts of matching lines, with each such part on a separate output line.
댓글 없음:
댓글 쓰기