例として以下のコンテンツを取り上げましょう
This file is a test file
this file is used to count the word 'file' in this test file
there are multiple occurrences of word file in some lines in this test file
上記の内容で「ファイル」という単語を数えたい。
以下のシェルコマンドを使用しています
cat $filename | sed "s/_/new/g" | sed "s/$word/_/g" | tr -c -d _ |wc -c
それは大丈夫ですか、それとももっと良いアイデアですか..?