RHEL6基础三十五之服务器维护基础命令⑤wc、paste

WC与Paste命令详解
本文详细介绍了Linux系统中WC命令的使用方法,包括统计文件的行数、字数及字节数等,并演示了如何利用Paste命令来合并多个文件的列,适用于需要处理文本文件的用户。

wc---Word Count

格式:wc [-选项] filename

功能:统计指定文件中的行数、字数、字节数,并将统计结果显示输出。

选项:

默认统计行数、字数、字节数三项,结果中不出现文件名通过管道实现

1
2
3
4
5
6
7
[root@justin ~]# cat /home/passwd
It is not only good to our health, but also to the environment.
There is no CO2 being produced as there are in cars. So it is very clean and green.
If you go to work by a bicycle instead of driving, you will get a better chance to get enough exercise.
[root@justin ~]# cat /home/passwd|wc
      3      52     253
[root@justin ~]#
-l  :统计行数;

1
2
3
[root@justin ~]# cat /home/passwd|wc -l
3
[root@justin ~]#
-w  :统计字数。一个字被定义为由空白、跳格或换行字符分隔的字符串;
1
2
3
[root@justin ~]# cat /home/passwd|wc -w
52
[root@justin ~]#

-c 统计字节数;

1
2
3
[root@justin ~]# cat /home/passwd|wc -c
253
[root@justin ~]#

-m  :统计字符数。这个标志不能与 -c 标志一起使用;

1
2
3
[root@justin ~]# cat /home/passwd|wc -m
253
[root@justin ~]#

-L 打印最长行的长度;

1
2
3
[root@justin ~]# cat /home/passwd|wc -L
104
[root@justin ~]#


paste---用于合并文件的列

paste [-s][-d <间隔字符>][--help][--version][文件...]

参数:

-d<间隔字符>或--delimiters=<间隔字符>  用指定的间隔字符取代跳格字符。

-s或--serial  串列进行而非平行处理,将一个文件中的多行数据合并为一行进行显示。

--help  在线帮助。

--version  显示帮助信息。

[文件…] 指定操作的文件路径

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
[root@localhost ~]# cat 1.txt 
1 a
[root@localhost ~]# cat 2.txt 
2 b
2 b
[root@localhost ~]# cat 3.txt 
3 c
3 c
3 c
[root@localhost ~]# paste 1.txt 2.txt 3.txt 
1 a    2 b    3 c
    2 b    3 c
        3 c
[root@localhost ~]# paste -d':' 1.txt 2.txt 3.txt 
1 a:2 b:3 c
:2 b:3 c
::3 c     
[root@localhost ~]# paste -s -d ';' 3.txt 
3 c;3 c;3 c
[root@localhost ~]# paste -s -d';' 3.txt 
3 c;3 c;3 c
[root@localhost ~]#




本文转自 justin_peng 51CTO博客,原文链接:http://blog.51cto.com/ityunwei2017/1335496,如需转载请自行联系原作者
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值