awk 中next的使用详解
来源:互联网 发布:mac文件复制到u盘里 编辑:程序博客网 时间:2024/05/21 01:52
直接看例子吧:
[root@centos-fuwenchao tmp]# more fileababcdef[root@centos-fuwenchao tmp]#
[root@centos-fuwenchao tmp]# awk '/^a/{print $0} /^a/{print $0}' fileababaa[root@centos-fuwenchao tmp]# awk '/^a/{print $0;next} /^a/{print $0}' file aba[root@centos-fuwenchao tmp]#
上面是不是要打印四行吖??????
[root@centos-fuwenchao tmp]# awk '/^a/{print $0;next} /^a/{print $0}' file fileabaaba[root@centos-fuwenchao tmp]#
[root@centos-fuwenchao tmp]# awk '/^a/{print $0;next}' file fileabaaba[root@centos-fuwenchao tmp]# awk '/^a/{print $0}' file fileabaaba[root@centos-fuwenchao tmp]# awk '/^a/{print $0;next}' fileaba[root@centos-fuwenchao tmp]# awk '/^a/{print $0}' fileaba[root@centos-fuwenchao tmp]#
awk '/^a/{next;print $0}' file这个什么也输出不来
======================
网上解释
遇到next时,读入下一行,然后从头开始处理,即next起到了{getline; goto head}的作用。
awk '/^a/{print $0;next} /^a/{print $0}' 用伪码可以这样来看:
:headif 匹配/^a/ print $0 读入下一行 goto headfiif 匹配/^a/ print $0figoto head
awk code: 'BEGIN{...}{Main Input}END{..}'
next 读入下一输入行并从(Main Input中的)第一个规则开始执行脚本。
现在可以解释为什么只有两行而不是四行了吧!
看下这个
[root@centos-fuwenchao tmp]# awk '/^a/{print $0;next} /^a/{print $0}' file fileabaadabaad[root@centos-fuwenchao tmp]#
先读取第一个输入,在读取第二个输入
假如我再这样
[root@centos-fuwenchao tmp]# awk '/^a/{print $0;next} /^a/{print $0}' file -abaad
他会处于等待状态 ,等待你从标准输入中输入数据
如果你是输入以a开头的,则再原样打印,否则什么也不输出!
0 0
- awk 中next的使用详解
- awk中next用法
- awk的next
- jdbc中next()的使用
- awk中next以及getline用法示例
- awk中next以及getline用法示例
- awk中next以及getline用法示例
- awk 多行合并(next)使用
- awk 多行合并【next 使用介绍】
- Linux下的awk使用详解
- awk的使用 第十一部分 awk中常用的模式
- shell中使用awk,awk引用shell变量的方法
- linux awk使用详解
- awk指令使用详解
- awk中如何使用shell的环境变量
- awk中如何使用shell的环境变量
- awk中使用shell的环境变量
- awk中如何使用shell的环境变量
- HDU 4022 Boming (Map , multiset)
- WebDriver启动IE失败
- 进程基础整理
- 第九章 函数(函数 声明 定义 形参 实参)总结 140512
- ubuntu手动安装redmine并且设置成为开机启动
- awk 中next的使用详解
- eaby技术架构变迁
- int b ,(!!b)相当于什么?
- MS SQl学习笔记
- 如何快速正确的安装 Ruby, Rails 运行环境
- Codeforces #245(div2)
- CocoaPods安装和使用教程
- 刘书高谈为什么要学习网络营销
- mongoskin查询语句的写法