누구든지 다음 두 명령 정규 표현식을 자세히 설명할 수 있습니까?

누구든지 다음 두 명령 정규 표현식을 자세히 설명할 수 있습니까?

텍스트 파일에서 두 번째 열의 0이 아닌 정수 수를 계산하는 데 사용되는 다음 두 명령입니다. 누구든지 정규식에 대해 자세히 설명해 주세요.

grep -c '^[^,]*,[^0][^,]*,' < myfile.txt
sed '/^[^,]*,0,.*/d' < myfile.txt | sed -n '$='

답변1

첫 번째 정규식은 다음을 포함하는 줄을 검색합니다.

'^        - start of line, followed by
 [^,]*    - 0 or more non-comma characters, followed by
 ,        - a comma, followed by
 [^0]     - any single character other than a zero, followed by
 [^,]*    - 0 or more non-comma characters, followed by
 ,'       - a comma

grep -c 일치하는 줄 수를 계산합니다.

두 번째 정규식 일치

'/        (the start of the regex)
 ^        - start of line, followed by
 [^,]*    - 0 or more non-comma characters, followed by
 ,0,      - a comma then a zero then a comma, followed by
 .*       - 0 or more other characters
 /d'      (the end of the regex -- delete the lines matching the preceding expression)

관련 정보