shell字符截取命令之awk命令

前端之家收集整理的这篇文章主要介绍了shell字符截取命令之awk命令前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_404_1@ 一 语法
@H_404_1@

@H_404_1@
@H_404_1@ 二 实战
@H_404_1@ [root@localhost ~]# cut -f 2,4 student.txt
@H_404_1@ furong 85
@H_404_1@ fengj 60
@H_404_1@ cang 70
@H_404_1@ [root@localhost ~]# awk '{printf $2 "\t" $4 "\n"}' student.txt @H_404_1@ furong 85 @H_404_1@ fengj 60 @H_404_1@ cang 70 @H_404_1@ [root@localhost ~]# awk '{print $2 "\t" $4}' student.txt @H_404_1@ furong 85 @H_404_1@ fengj 60 @H_404_1@ cang 70 @H_404_1@ [root@localhost ~]# df -h|awk '{print $1 "\t" $3}' @H_404_1@ Filesystem Used @H_404_1@ /dev/sda3 124M @H_404_1@ devtmpfs 0 @H_404_1@ tmpfs 84K @H_404_1@ tmpfs 7.0M @H_404_1@ tmpfs 0 @H_404_1@ /dev/sda5 3.9G @H_404_1@ /dev/sda7 33M @H_404_1@ /dev/sda2 1.3G @H_404_1@ /dev/sda1 153M @H_404_1@ tmpfs 16K @H_404_1@ tmpfs 0 @H_404_1@ @H_404_1@ 三 在awk命令的输出支持print和printf命令 @H_404_1@

@H_404_1@ @H_404_1@ 四 实战 @H_404_1@ [root@localhost ~]# df -h|grep "/dev/sda5" |awk '{print $5}' @H_404_1@ 39% @H_404_1@ [root@localhost ~]# df -h|grep "/dev/sda5" |awk '{print $5}'|cut -d "%" -f 1 @H_404_1@ 39 @H_404_1@ [root@localhost ~]# awk 'BEGIN{printf "This is a transcript \n"}{printf $2 "\t" $4 "\n"}' student.txt @H_404_1@ This is a transcript @H_404_1@ furong 85 @H_404_1@ fengj 60 @H_404_1@ cang 70 @H_404_1@ [root@localhost ~]# awk 'END{printf "This is a transcript \n"}{printf $2 "\t" $4 "\n"}' student.txt @H_404_1@ furong 85 @H_404_1@ fengj 60 @H_404_1@ cang 70 @H_404_1@ This is a transcript @H_404_1@ [root@localhost ~]# cat /etc/passwd | grep "/bin/bash" @H_404_1@ root:x:0:0:root:/root:/bin/bash @H_404_1@ cakin24:x:1000:1000:cakin24,cakin,cakin:/home/cakin24:/bin/bash @H_404_1@ test:x:1003:1001::/home/xxx:/bin/bash @H_404_1@ cls:x:1001:1001:dgdzmx:/home/cls:/bin/bash @H_404_1@ [root@localhost ~]# cat /etc/passwd | grep "/bin/bash"|\ @H_404_1@ > awk 'BEGIN{FS=":"}{printf $1 "\t" $3 "\n"}' @H_404_1@ root 0 @H_404_1@ cakin24 1000 @H_404_1@ test 1003 @H_404_1@ cls 1001 @H_404_1@ [root@localhost ~]# cat student.txt |awk '$4>=70{printf $2 "\n"}' @H_404_1@ furong @H_404_1@ cang

猜你在找的Bash相关文章