- 论坛徽章:
- 18
|
本帖最后由 bikkuri 于 2014-08-23 16:43 编辑
我的版本是3.1.7。- [root@cloudband-be E]# awk --version
- GNU Awk 3.1.7
- Copyright (C) 1989, 1991-2009 Free Software Foundation.
复制代码 可能是编译的时候没有加--enable-switch选项,所以不支持switch语句。
If gawk is configured with the --enable-switch option to the configure command, then it accepts an additional
control-flow statement:
switch (expression) {
case value|regex : statement
...
[ default: statement ]
}
If gawk is configured with the --disable-directories-fatal option, then it will silently skip directories named
on the command line. Otherwise, it will do so only if invoked with the --traditional option.
http://stackoverflow.com/questions/11401979/switch-case-doesnt-work-in-awk
用if语句替换掉switch语句后没有出错了,但是输出的结果不正确。- [root@cloudband-be E]# strings E9C79540610 |awk -v OFS="|" -v FPAT='(Date|Username|Password|E-mail):[^N]*' '{for(i=1;i<=NF;i++){if (
- $i~/Date/){d=$i;break;}if ($i~/Username/){u=$i;break;}if ($i~/Password/){p=$i;break;}if ($i~/E-mail/)e=$i;}}END{print u,e,p,d}'
- Username:||Password:|(UTC)N+Date:
复制代码- [root@cloudband-be E]# strings E9C79540610 |awk -v OFS="|" -v FPAT='(Date|Username|Password|E-mail):[^N]*' '{for(i=1;i<=NF;i++){if (
- $i~/Date/){d=$0;break;}if ($i~/Username/){u=$0;break;}if ($i~/Password/){p=$0;break;}if ($i~/E-mail/)e=$0;}}END{print u,e,p,d}'
- Username: kamemiya N$E-mail: kiyoshi.amemiya@ibm.com N||Password: fpMMduNF N|N!Return-Path: <foo@cloud-band.com>N9Received: from c
- loudband-be.local (localhost [127.0.0.1])N: by cloudband-be.local (Postfix) with ESMTP id 571345405FANI for <kiyoshi.amemiya
- @ibm.com>; Fri, 22 Aug 2014 08:21:01 +0000 (UTC)N+Date: Fri, 22 Aug 2014 08:21:01 +0000 (UTC)N
复制代码 看来FPAT也没起作用。
好像FPAT只适用于GNU awk 4 以上版本。

blackold 发表于 2014-08-23 15:28 ![]()
回复 10# bikkuri |
|