Anzahl der zeichen Zählen
Moin! Wie kann ich herausfinden, wie oft ein bestimmtes Zeichen in einer Datei vorkommt? (in bash) Olli
Matthias Strack wrote:
At 10:45 13.12.2002 +0100, Antwerpen, Oliver wrote:
Wie kann ich herausfinden, wie oft ein bestimmtes Zeichen in einer Datei vorkommt? (in bash)
cat DATEI|grep (-i) ZEICHEN| wc -m
Glaube nicht, dass das richtig ist. Grep wird Dir die gesamte Zeile ausgeben - Du zaehlst also die vorhandenen Zeichen in den Zeilen, in denen ZEICHEN vorkommt. Das ist aber nicht das Gleiche wie die Anzahl von vorkommenden ZEICHEN in der Datei DATEI! Gruesse, Th. -- Thomas Hertweck, Geophysicist Geophysical Institute, Karlsruhe University (TH)
hallo, eine reine bash-loesung geht bestimmt, jedoch faellt mir dazu im augenblick nichts ein. in perl koennte das so aussehen. -- snipp #! /usr/local/bin/perl use strict; use warnings; my ($file,$str) = @ARGV; open(FILE,$file) or die "kann die Datei $file nicht öffnen"; my $count = 0; while (<FILE>) { while ($_ =~ /$str/g) { $count++; } } close(FILE); print $count,"\n"; --snap ein aufruf markus@sam:~/prog/myperl> mc mc e 14 markus@sam:~/prog/myperl> gruss markus Matthias Strack wrote:
Gude,
At 10:45 13.12.2002 +0100, Antwerpen, Oliver wrote:
Moin!
Wie kann ich herausfinden, wie oft ein bestimmtes Zeichen in einer Datei vorkommt? (in bash)
cat DATEI|grep (-i) ZEICHEN| wc -m
eine Möglichkeit unter vielen vermute ich.
tschö
Hallo, On Fri, 13 Dec 2002, Antwerpen, Oliver wrote:
Wie kann ich herausfinden, wie oft ein bestimmtes Zeichen in einer Datei vorkommt? (in bash)
Nicht bash, aber awk: awk '{ cnt += gsub("ZEICHEN","&"); } END { print cnt; }' DATEI (cnt wird implizit zu 0 initialisiert) -dnh -- 122: Updateritis Softwarebulemie (Frank Klemm)
participants (5)
-
Antwerpen, Oliver
-
David Haller
-
Matthias Strack
-
Thomas Hertweck
-
wmarkusw@t-online.de