shell字符截取命令之awk命令
来源:互联网 发布:网络基础知识学习 编辑:程序博客网 时间:2024/09/21 09:23
一 语法
二 实战
[root@localhost ~]# cut -f 2,4 student.txt
furong 85
fengj 60
cang 70
[root@localhost ~]# awk '{printf $2 "\t" $4 "\n"}' student.txt
furong 85
fengj 60
cang 70
[root@localhost ~]# awk '{print $2 "\t" $4}' student.txt
furong 85
fengj 60
cang 70
[root@localhost ~]# df -h|awk '{print $1 "\t" $3}'
Filesystem Used
/dev/sda3 124M
devtmpfs 0
tmpfs 84K
tmpfs 7.0M
tmpfs 0
/dev/sda5 3.9G
/dev/sda7 33M
/dev/sda2 1.3G
/dev/sda1 153M
tmpfs 16K
tmpfs 0
三 在awk命令的输出中支持print和printf命令
四 实战
[root@localhost ~]# df -h|grep "/dev/sda5" |awk '{print $5}'
39%
[root@localhost ~]# df -h|grep "/dev/sda5" |awk '{print $5}'|cut -d "%" -f 1
39
[root@localhost ~]# awk 'BEGIN{printf "This is a transcript \n"}{printf $2 "\t" $4 "\n"}' student.txt
This is a transcript
furong 85
fengj 60
cang 70
[root@localhost ~]# awk 'END{printf "This is a transcript \n"}{printf $2 "\t" $4 "\n"}' student.txt
furong 85
fengj 60
cang 70
This is a transcript
[root@localhost ~]# cat /etc/passwd | grep "/bin/bash"
root:x:0:0:root:/root:/bin/bash
cakin24:x:1000:1000:cakin24,cakin,cakin,cakin:/home/cakin24:/bin/bash
test:x:1003:1001::/home/xxx:/bin/bash
cls:x:1001:1001:dgdzmx:/home/cls:/bin/bash
[root@localhost ~]# cat /etc/passwd | grep "/bin/bash"|\
> awk 'BEGIN{FS=":"}{printf $1 "\t" $3 "\n"}'
root 0
cakin24 1000
test 1003
cls 1001
[root@localhost ~]# cat student.txt |awk '$4>=70{printf $2 "\n"}'
furong
cang
阅读全文
0 0
- shell字符截取命令之awk命令
- Shell编程-字符截取命令-awk命令
- 字符截取命令-awk命令
- shell字符截取命令之cut命令
- [Shell]字符截取命令:cut, printf, awk, sed
- Shell 字符截取命令:cut, printf, awk, sed
- shell命令之awk
- Shell 命令之 awk
- shell-字符截取命令sed
- shell编程-字符截取命令
- Shell编程-字符截取命令-cut命令
- Shell编程-字符截取命令-printf命令
- Shell编程-字符截取命令-sed命令
- Linux Shell之awk命令
- 11 shell命令之awk
- Shell基础之-awk命令
- Linux之字符截取命令
- shell笔记(5):字符截取命令
- 字符处理命令sort和wc
- transient关键字与序列化
- tp不使用表前缀写法
- springMVC的快速搭建------Java配置
- C#和MATLAB混合编程
- shell字符截取命令之awk命令
- 你的解耦战术,决定了架构高度!
- maven介绍及环境搭建
- Shell条件判断语句上
- 序列化中子父类构造函数问题
- 选择排序
- shell条件判断式语句中
- shell条件判断式语句下
- maven常用的构建命令