你好再次stackoverflow!
我有一个非常大的平面文件,我希望导出匹配 2 种不同模式的所有记录。问题是每条记录中的行数不同,并且记录相互渗透。记录的最后一行是 Door ID,第一行是 User: 。
我正在针对电子邮件地址中的@ 进行测试,并且上次登录包含“登录时间:2013-08”。我需要导出所有行,包括电子邮件地址行和最后登录行。以下是 2 个样品。我试过像这样使用awk:
awk '/login time: 2013-08/{e=0}/@ /{gsub("^.*@ ","",$0);e=1}{if(e==1){print}}' filename
当然失败了....
所以这是示例数据
User: afshin@runners.org
First Name: Afshi
Last Name: Noghami
Is Delegated Admin: False
IP Whitelisted: False
Account Suspended: False
Must Change Password: False
Unique ID: 102209840259208897543
ID TPYE: Cx4
Creation Time: 2013-06-07T04:14:42.000Z
Last login time: Never
Path: /Members/Inactive
IMs:
Addresses:
Organizations:
Phones:
Relations:
Door IDs:
User: jjnalli@runners.org
First Name: JISS
Last Name: NALLIKUZHY
Is a Super Admin: False
Is Delegated Admin: False
Has Agreed to Terms: True
IP Whitelisted: False
Account Suspended: False
Must Change Password: False
Unique ID: 109765147242431344122
ID TYPE: Cx4
Mailbox setup: True
Included: False
Creation Time: 2013-06-07T03:32:52.000Z
Last login time: 2013-08-02T07:13:02.000Z
Path: /Members/Inactive
IMs:
Addresses:
Organizations:
Phones:
Relations:
Door IDs:
对于具有最后登录日期的每条记录,所需的输出如下所示:
User: jjnalli@runners.org
First Name: JISS
Last Name: NALLIKUZHY
Is a Super Admin: False
Is Delegated Admin: False
Has Agreed to Terms: True
IP Whitelisted: False
Account Suspended: False
Must Change Password: False
Unique ID: 109765147242431344122
ID TYPE: Cx4
Mailbox setup: True
Included: False
Creation Time: 2013-06-07T03:32:52.000Z
Last login time: 2013-08-02T07:13:02.000Z