Linux 中 head -c截取无换行符的字符

发布时间 2023-10-12 11:57:11作者: 小鲨鱼2018

 

001、

[root@pc1 test2]# ls
a.txt
[root@pc1 test2]# cat a.txt
01 02 1
03 04 2
05 06 3
07 08 4
09 10 5
11 12 6
13 14 7
15 16 8
17 18 9
19 20 10
21 22 11
23 24 12
25 26 13
[root@pc1 test2]# cat a.txt | head -c 3    ## 截取前3个无换行符的字符,(head是对整个文件而言)
01 [root@pc1 test2]#

 

002、cut -c截取带空格

[root@pc1 test2]# ls
a.txt
[root@pc1 test2]# head a.txt
01 02 1
03 04 2
05 06 3
07 08 4
09 10 5
11 12 6
13 14 7
15 16 8
17 18 9
19 20 10
[root@pc1 test2]# cat a.txt | head -n 1 | cut -c 1-3    ## cut以行为单位,带有换行符
01

 。