一、作用
-
二、选项
-F # 改变FS值(分隔符)
$n # 当前记录的第 n 个字段,字段间由 FS 分隔
$0 # 完整的输入记录
NF # 当前记录中的字段数(列) 【最后一列】
NR # 当前行数 【第一列】
三、实例
案例{ free -h | grep Mem |awk -F' ' '{print $2}' free -h | grep Mem |awk -F' ' '{print $(NF-1)}' free -h | awk '{if(NR==2){print $2}}' #获取第二行第二列 free -h | awk '{if(NR==2){print $2"\t"$3"\t"$4}}' }
[root@localhost ~]# free -h | grep Mem |awk -F' ' '{print $2}' 1.8G
```shell [root@localhost ~]# free -h | grep Mem |awk -F’ ‘ ‘{print $(NF-1)}’ 394M
```shell
[root@localhost ~]# free -h | awk '{if(NR==2){print $2}}'
1.8G
[root@localhost ~]# cat /etc/passwd |sed -n '2,5p' |awk -F':' '{if(NR==3){print $1":"$2}}'
sync:x
[root@localhost ~]# cat /etc/passwd |sed -n '2,5p' |awk -F':' '{if(NR==3){print $1"\t"t$2}}'
sync x