cut最后几位 shell_shell特殊符_cut截取,sort排序,shell特殊符号

cut 命令

cut作用:截取字符串

用法如下:cat /etc/passwd |head -2 |cut -d ":" -f 1,2,4

在管道符后面进行截取前面命令的输出。

cut -d " " 指定分割条件,比如 ":" ,就是以:进行分割。每到一个:就是一段。

-f 是指定截取哪一段。后面跟数字几,就是截取几段。如果想1到4段都要。就是-f 1-4

[root@localhost ~]# cat /etc/passwd |head -2

root:x:0:0:root:/root:/bin/bash

bin:x:1:1:bin:/bin:/sbin/nologin

[root@localhost ~]# cat /etc/passwd |head -2 |cut -d ":" -f 1

root

bin

[root@localhost ~]# cat /etc/passwd |head -2 |cut -d ":" -f 1,2

root:x

bin:x

[root@localhost ~]# cat /etc/passwd |head -2 |cut -d ":" -f 1,2,4

root:x:0

bin:x:1

还有一种用法是 : -c,指定截取第几位,比如截取etc/passwd 的第四位。

[root@localhost ~]# cat /etc/passwd |head -2 |cut -c 4

t

:

排序命令: sort

用法: sort 加想要查看的文件

排序方式:没有环境变量影响的话,默认按照ASCLL码排序。

新建一个文本,cat内容如下:

[root@localhost ~]# cat 1.txt

43

35

67

907890

hrshs

hsga

agsfh

.,12125

43

&%#@

^$%$

@%#

用sort进行排序后内容如下:

[root@localhost ~]# sort 1.txt

^$%$

@%#

&%#@

.


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部