Shell-Script zum Zählen der Vorkommen eines Wortes in einer Datei

Nehmen wir die unterhalb des Inhalts als Beispiel

    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

Ich zählen will das Wort 'Datei' in der oben genannten Inhalte.

Bin ich unter den unten angegebenen shell-Befehl

   cat $filename |  sed "s/_/new/g" | sed "s/$word/_/g" | tr -c -d _ |wc -c

Ist das ok oder besser Ideen ..?

InformationsquelleAutor Manikanda raj S | 2012-08-06

Schreibe einen Kommentar