使用grep和wc计算文件中的行数

使用grep和wc计算文件中的行数

本文介绍了使用grep和wc计算文件中的行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用grep和带有管道的字数统计(wc -l)在文件中显示多行.

I am trying to display a number of lines in a file using grep and word count (wc -l) with a pipe.

我尝试了许多不同的方法,但都没有言辞.该文件位于/home/[用户]/[文件夹]/[文件名.扩展名].

I tried many different methods but neither of them wordked. The file is in /home/[User]/[Folder]/[File Name.Extension].

任何建议都值得赞赏.

谢谢

推荐答案

您不需要grep即可计算行数,wc就足够了:

You don't need grep to count the number of lines, wc is sufficient :

wc -l filename

应该工作.

grep仅在您不想过滤文件内容(例如,您要计算包含单词life的行数)时才有用,然后:

grep is useful only if you wan't to filter the file content, say you want to count the number of lines that contain the word life, then :

grep "life" filename | wc -l

将为您提供结果.

这篇关于使用grep和wc计算文件中的行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 18:40
查看更多