次の2つのコマンドの正規表現を詳しく説明できる人はいますか?

次の2つのコマンドの正規表現を詳しく説明できる人はいますか?

次の 2 つのコマンドは、テキスト ファイルの 2 番目の列の非ゼロ整数の数をカウントするために使用されます。正規表現を詳しく説明していただける方はいらっしゃいますか。

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は一致する行の数を数える

2番目の正規表現は

'/        (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)

関連情報