且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2022-10-03 19:58:51

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,如需转载请自行联系原作者