Linux下wc命令统计文件行数/词数/字符数/最长行字符数
wc命令帮助
$ wc --help
Usage: wc [OPTION]... [FILE]...
or: wc [OPTION]... --files0-from=F
Print newline, word, and byte counts for each FILE, and a total line if
more than one FILE is specified. A word is a non-zero-length sequence of
characters delimited by white space. With no FILE, or when FILE is -, read standard input. The options below may be used to select which counts are printed, always in
the following order: newline, word, character, byte, maximum line length.
-c, --bytes print the byte counts
-m, --chars print the character counts
-l, --lines print the newline counts
--files0-from=F read input from the files specified by
NUL-terminated names in file F;
If F is - then read names from standard input
-L, --max-line-length print the maximum display width
-w, --words print the word counts
--help display this help and exit
--version output version information and exit GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
Full documentation at: <http://www.gnu.org/software/coreutils/wc>
or available locally via: info '(coreutils) wc invocation'
命令使用
统计行数
$ wc -l /usr/share/dict/american-english
/usr/share/dict/american-english
统计词数
$ wc -w /usr/share/dict/american-english
/usr/share/dict/american-english
统计字符数
wc -m /usr/share/dict/american-english
/usr/share/dict/american-english
统计字节数
wc -c /usr/share/dict/american-english
/usr/share/dict/american-english
注意-c和-m的区别在于对于多字节字符, 例如GBK, UTF-8编码的中文, 在-m中记一个, 在-c中记多个, 例如下面的测试, ubuntu默认编码是UTF-8, 中文是3个字节
$ echo -n "123, 测试"|wc -c $ echo -n "123, 测试"|wc -m
统计最长的行
$ wc -L /usr/share/dict/american-english
/usr/share/dict/american-english
如果只希望获取数字, 不打印文件名, 可以通过以下两种方法, 从节约内存的角度看, 推荐前一种方法
$ wc -l /usr/share/dict/american-english | awk '{print $1}'
$ cat /usr/share/dict/american-english | wc -l
Linux下wc命令统计文件行数/词数/字符数/最长行字符数的更多相关文章
- linux 使用wc命令统计文件行数、字数及大小
语法:wc [选项] 文件… 说明:该命令统计给定文件中的字节数.字数.行数.如果没有给出文件名,则从标准输入读取.wc同时也给出所有指定文件的总统计数.字是由空格字符区分开的最大字符串. 该命令各选 ...
- 【Linux】常用命令-统计代码行数
公司人员流动大,经常有新的维护任务,交接时喜欢看看新来的模块的代码量,那么问题来了, 如何统计代码行数? 1,最先想到的肯定是 wc. wc -l *.h 将查看[当前目录]下头文件的代码行数,输出结 ...
- linux下sed命令对文件执行文本替换
让我们看一下 sed 最有用的命令之一,替换命令.使用该命令,可以将特定字符串或匹配的规则表达式用另一个字符串替换.下面是该命令最基本用法的示例: $ sed -e ‘s/foo/bar/’ myfi ...
- linux下vi命令修改文件及保存的使用方法
进入vi的命令 vi filename :打开或新建文件,并将光标置于第一行首 vi n filename :打开文件,并将光标置于第n行首 vi filename :打开文件,并将光标置于一行首 v ...
- (转)linux下vi命令修改文件及保存的使用方法
进入vi的命令 vi filename :打开或新建文件,并将光标置于第一行首 vi n filename :打开文件,并将光标置于第n行首 vi filename :打开 ...
- Linux wc -l 统计文件行数存在的问题
1.使用这种方式效率较低,而且不注意可能出现错误 find . -name "*.pc" |xargs wc -l 直接查看 total 不是正确的值. 原因: 这种方式存在一个 ...
- Linux下wc命令详解
功能说明:计算字数. 语 法:wc [-clw][--help][--version][文件…] 补充说明:利用wc指令我们可以计算文件的Byte数.字数.或是列数,若不指定任何文件名称,或是所给 ...
- win7和linux下利用命令查看文件md5、sha1、sha256
win7 certutil -hashfile <filename> MD5 certutil -hashfile <filename> SHA1 certutil -hash ...
- Linux下Sed命令替换文件中的所有IP
命令: sed -ri 's/([0-9]{1,3}\.){3}[0-9]{1,3}/localhost/g' es_create_index.sh 如图:
随机推荐
- BZOJ1337: 最小圆覆盖
题目:求n个点的最小圆覆盖. 题解:最小圆覆盖,上模板.复杂度证明可以戳:这里 代码: #include<cstdio> #include<cstdlib> #include& ...
- iOS "directory not found for option '-L/Users/.../Pods/build/Debug-iphoneos"解决方式
问题重述: 在删掉原来工作空间,又一次install pods之后,遇到warning: ld: warning: directory not found for option '-L/Users/. ...
- iOS开发文件夹--Copy items if needed
蓝色文件夹 蓝色文件夹(folder)一般作为资源文件夹使用,与黄色文件夹的主要区别是不参与编译,所以说如果你在这些文件夹下编写的逻辑代码是不参与编译的,其他文件也不能直接引用它们,若引用其中文件需要 ...
- Restore IP Addresses leetcode java
题目: Given a string containing only digits, restore it by returning all possible valid IP address com ...
- Laravel学习笔记之Session源码解析(下)
说明:在中篇中学习了session的CRUD增删改查操作,本篇主要学习关闭session的相关源码.实际上,在Laravel5.3中关闭session主要包括两个过程:保存当前URL到session介 ...
- Android -- 处理ViewPager的notifyDataSetChanged无刷新
Viewpager在调用notifyDataSetChanged()时,界面无刷新 Viewpager在调用notifyDataSetChanged()时,界面无刷新,它确实影响我们功能的实现了.可能 ...
- ML&DL视频教程资源
作者:Bruce链接:https://www.zhihu.com/question/49909565/answer/345894856来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载 ...
- C# Winform 未能加载文件或程序集"System.Data.SQLite"或它的某一个依赖项。试图加载格式不正确的程序
在使用Winform 开发了一个小软件,其中使用了SQLite作为数据库 但在我的Win7 64位系统上却出现了以下错误: System.BadImageFormatException: 未能加载文件 ...
- 判断一个整数是否是2的n次方
参考:http://bbs.csdn.net/topics/370058619 如题,如何判断一个整数是否是2的N次方,我能想到的方法有两个 1.一直除2,看最后是否等于1.(最笨的方法) 2.转换成 ...
- OpenWrt Web界面修改及功能实现实例说明
http://www.cnblogs.com/dwayne/archive/2012/04/21/2460830.html 通过上篇文章的介绍,我们应该了解了Lua语言在OpenWrt Web配置页面 ...