Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
BASH—快速确定文件中以大写字母开头的行数_Bash_File_Lines_Counting - Fatal编程技术网

BASH—快速确定文件中以大写字母开头的行数

BASH—快速确定文件中以大写字母开头的行数,bash,file,lines,counting,Bash,File,Lines,Counting,如何快速确定文件中以大写字母开头的行数 我认为使用正则表达式这将是[A-Z]*),但我不想“读行”。。。 更快的方法。如果您不想使用读取循环,最好的选择是使用grep,使用-c开关计算匹配行数,如下所示: grep -c ^[A-Z] the_file.txt 谢谢,太好了:)我如何测量反应时间?根据文件的内容,字符类[[:upper:]比[A-Z]root@linux:~#时间(grep-c^[A-Z]/root/list)1005578real 0m0.192suser 0m0.178ss

如何快速确定文件中以大写字母开头的行数

我认为使用正则表达式这将是[A-Z]*),但我不想“读行”。。。
更快的方法。

如果您不想使用
读取
循环,最好的选择是使用
grep
,使用
-c
开关计算匹配行数,如下所示:

grep -c ^[A-Z] the_file.txt

谢谢,太好了:)我如何测量反应时间?根据文件的内容,字符类
[[:upper:]
[A-Z]
root@linux:~#时间(grep-c^[A-Z]/root/list)
1005578
real 0m0.192s
user 0m0.178s
sys 0m0.011s
适用于非英语语言。例如
printf“%s\n”{A..Z}È
--尝试用
grep-v'[A-Z]'
过滤,然后用
grep-v'[[:upper:]]'
root@linux:~#时间(grep-c^[:upper:]/root/list)
1005578
real 0m0.188s
用户0m0.165s
系统0m0.018s