1. 字段(列)提取命令:cut [选项] 文件名
选项: - f 列号(提取第几列) - d 分隔符(按照指定分隔符分割列)
[root@localhost sh]# cat student.txt ID Name Gender Mark 1 alex male 11 2 boby male 22 3 cyan male 33 4 dauge male 44 [root@localhost sh]# cut -f 2 student.txt # -f 设置列号 Name alex boby cyan dauge [root@localhost sh]# cut -f 2,4 student.txt Name Mark alex 11 boby 22 cyan 33 dauge 44 [root@localhost sh]# grep "/bin/bash" /etc/passwd | grep -v "root" # -v 取反 user1:x:502:502::/home/user1:/bin/bash user2:x:503:503::/home/user2:/bin/bash [root@localhost sh]# grep "/bin/bash" /etc/passwd | grep -v "root" | cut -f 1 -d ":" # -d 设置分隔符
2. 格式化输出命令:pritf '输出类型 输出格式' 输出内容
[root@localhost sh]# cat student.txt ID Name Gender Mark 1 alex male 11 2 boby male 22 3 cyan male 33 4 dauge male 44 [root@localhost sh]# printf '%s %s %s %s ' $(cat student.txt) ID Name Gender Mark 1 alex male 11 2 boby male 22 3 cyan male 33 4 dauge male 44
3. awk 命令
4. sed 命令