
[英]Linux command to find a specific line in file and add new lines below it
[英]from Linux command line, find number of lines in which a string occurs
我在/home/someuser/sometext.txt位置有一个文件。 我想计算特定字符串出现的行数。 从Linux命令行执行此操作的方法是什么?
grep with -c
switch是你需要的:
grep -c "pattern" /home/someuser/sometext.txt
使用awk的替代解决方案:
awk '/regex/{c++}END{print c+0}' /home/someuser/sometext.txt
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.