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 如图:
随机推荐
- noip 1998 洛谷P1013 进制位
题目描述 著名科学家卢斯为了检查学生对进位制的理解,他给出了如下的一张加法表,表中的字母代表数字. 例如: L K V E L L K V E K K V E KL V V E KL KK E E K ...
- Verilog 加法器和减法器(4)
类似于行波进位加法器,用串联的方法也能够实现多位二进制数的减法操作. 比如下图是4位二进制减法逻辑电路图. 8位二进制减法的verilog代码如下: module subn(x, y, d,cin) ...
- 什么是L2 frame?
The data link layer or layer 2 is the second layer of the seven-layer OSI model of computer networki ...
- JS读取XML文件数据并以table显示数据(兼容IE火狐)
先看xml文件: <?xml version="1.0" standalone="yes"?> <student> <stuinf ...
- Populating Next Right Pointers in Each Node leetcode java
题目: Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode ...
- Flyweight 享元模式 MD
享元模式 简介 在JAVA语言中,String类型就是使用了享元模式,JAVA中的字符串常量都是存在常量池中的,JAVA会确保一个字符串常量在常量池中只有一个拷贝,避免了在创建N多相同对象时所产生的不 ...
- wifidog 源码初分析(1)-转
wifidog 的核心还是依赖于 iptables 防火墙过滤规则来实现的,所以建议对 iptables 有了了解后再去阅读 wifidog 的源码. 在路由器上启动 wifidog 之后,wifid ...
- PHPExcel合并与拆分单元格
$objPHPExcel; $filepath="c:\temp.xlsx"; try { $objReader = PHPExcel_IOFactory::createRea ...
- GIT 如何合并另一个远程Git仓库的文件到本地仓库里某个指定子文件夹并不丢失远程提交记录?
问题背景: 最近在重新整理手中的一个项目,目前该项目分为PC项目,手机项目,某第三方接口项目,第三方接口服务项目和手机项目 因为之前规划的原因,原来的四个项目是分两个解决方案来管理的 ...
- 转:在centos安装与启动mysql
一. 下载与安装过程相录详细 相当详细推荐.digitalocean.com 这个网站的东西,很详细,很专业. https://www.digitalocean.com/community/tutor ...