字符截取

字符截取命令:
cut
awk
sed
printf

cut -f 列号 :
cut -d 分隔符 :

举例:
#!/bin/bash
ID Name gender mark
1 sl M 89
2 hus M 90
3 sd M 99


提取第二列:
[root@localhost tmp]# cut -f 2 student.txt
#!/bin/bash
Name
sl
hus
sd


提取第2,3列
[root@localhost tmp]# cut -f 2,3 student.txt
#!/bin/bash
Name gender
sl M
hus M
sd M

[root@localhost tmp]# cat /etc/passwd | grep /bin/bash |grep -v root | cut -d ":" -f 1
zhangsan
user1
user2
user3

说明:取出/etc/passwd 中添加的普通用户
grep -v :排除
cut -d ":" :用冒号分割

原文地址:https://www.cnblogs.com/javasl/p/11155148.html