English 中文(简体)
与全球代表处一起出现一个短语的情况
原标题:Count the occurrences of a phrase with GREP
  • 时间:2012-05-11 16:24:27
  •  标签:
  • unix
  • grep

与全球代表处一起出现一个短语的情况

我有一份档案目录,载有档案目录。 因此,当我需要看看是否有任何档案含有某种短语时,我就使用过。

www.un.org/chinese/ga/president

Is there any way to count the total number of times that the phrase appears in these files?

页: 1

But that d give the occurrences in each individual file, not the total, which is not what I want.

最佳回答

应:

find mydir -print0 | xargs -0 grep  the phrase  | wc -l

<代码>定本ir0——将所有档案都放在单头上,并作为终止的线打印。

xargs -0 - 转换一流已终止的线体,将其改为引证其论点,例如,“mydir/file 1”“mydir/file 2”......现在可以将这些论点列入碎.清单。

<代码>wc-l>->

彻底终止的线索业务都与在档案中拥有空间的工作有关,因为否则,这些档案可能像多条论据一样 gr。

问题回答

这比前两项答复更加简单:

grep  the phrase  mydir/* | wc -l

The output of grep across all files that match "mydir/*" is then sent to wc -l.

grep  the phrase  mydir/* --count | awk  BEGIN { FS=":"; sum=0;} { sum = sum + $2; } END { print sum }  




相关问题
Really strange grep 2.5.1 bug in cat d reading long lines

Recently a peer and I discovered an interesting bug in GNU grep 2.5.1 in which standard input with lines greater than 200,000,000 characters causes grep to fail, even if the pattern is not in one of ...

grep a tab in UNIX

How do I grep tab ( ) in files on the Unix platform?

how to grep a variable in the shell program? [duplicate]

#!/bin/bash for ((var=0; var<20; var++)) do echo " Number is: $(grep Multiple_Frame = echo **$var** 20mrf.txt | wc -l)" >>statisic.txt done This shell program cannot produce correct ...

GREP - finding all occurrences of a string

I am tasked with white labeling an application so that it contains no references to our company, website, etc. The problem I am running into is that I have many different patterns to look for and ...

Grep doesn t work correctly with .as files

Here s the statement I m running: grep -i -H ConfigureControls *.as Note that I m forcing file names with the -H flag. What I get back is: } } trac} } this.chairControls.debug....

热门标签