awk打印电子邮件ID

时间:2016-04-18 15:33:03

标签: shell awk

我正在尝试从文本文件中提取一些电子邮件ID但是当我运行awk时我得到一个空白。当我尝试grep寻找另一种模式时,这似乎也有效。

--------
Mess1288I: Message 'com.admin.AdminServices' on jvm 'MACHINE1' is running.

Additional thread instances: '0'
Deployed: '2/16/16 12:15 PM' in jar file '/www/deploy/dev/MACHINE1/AdminServicesDEV_2015-09-02_00-04-31.jar'
Last edited: '9/2/15 10:25 AM'
UUID: '848c53b2-5201-0000-0080-9c722b3eca55'
Start mode: 'Maintained'
Long description: ''
User-defined property names:
  'ApplicationSupportGroup' = 'Integration'
  'EVENTTYPE' = 'Integration_RequestReceived'
  'LoggingProgramName' = 'GetCustomerByAdmin'

Keywords:

--------
Mess1288I: Message 'com.authentication.AuthenticationService' on jvm 'MACHINE1' is running.

Additional thread instances: '0'
Deployed: '2/16/16 12:15 PM' in jar file '/www/deploy/dev/MACHINE1/AuthenticationServiceDEV_2014-11-06_07-18-34.jar'
Last edited: '11/6/14 6:47 PM'
UUID: '84b753b2-5201-0000-0080-9c722b3eca55'
Start mode: 'Maintained'
Long description: ''
User-defined property names:
  'ApplicationSupportGroup' = 'Integration'
  'EVENTTYPE' = 'Integration_RequestSent'
  'LoggingProgramName' = 'AuthenticationService'

Keywords:

--------
Mess1288I: Message 'com.authentication.MergeReply' on jvm 'MACHINE1' is running.

Additional thread instances: '0'
Deployed: '2/16/16 12:16 PM' in jar file '/www/deploy/dev/MACHINE1/AccountMergeDEV_2015-08-06_14-33-47.jar'
Last edited: '8/3/15 3:42 PM'
UUID: '1fda53b2-5201-0000-0080-9c722b3eca55'
Start mode: 'Maintained'
Long description: ''
User-defined property names:
  'AlertEmailList' = 'authenticationalerts@hotmail.com'
  'ApplicationSupportGroup' = 'Integration'
  'EVENTTYPE' = 'Integration_ResponseSent'
  'LogLevel' = 'ERROR'
  'LoggingProgramName' = 'MergeReply'
  'MaxPerInterval' = '5'
  'NotificationInterval' = '300'
Keywords:

--------
Mess1289I: Message 'com.authentication.Eligibility' on jvm 'MACHINE1' is stopped.

Additional thread instances: '0'
Deployed: '2/16/16 12:16 PM' in jar file '/www/deploy/dev/MACHINE1/AccountMergeDEV_2015-08-06_14-33-47.jar'
Last edited: '8/3/15 3:42 PM'
UUID: '5fda53b2-5201-0000-0080-9c722b3eca55'
Start mode: 'Maintained'
Long description: ''
User-defined property names:
  'AlertEmailList' = 'authenticationalerts@hotmail.com'
  'ApplicationSupportGroup' = 'Integration'
  'EVENTTYPE' = 'Integration_ResponseSent'
  'LogLevel' = 'ERROR'
  'LoggingProgramName' = 'CheckMergeEligibility'
  'MaxPerInterval' = '5'
  'NotificationInterval' = '300'
Keywords:

--------
Mess1288I: Message 'com.authentication.MergeRequest' on jvm 'MACHINE1' is running.

Additional thread instances: '0'
Deployed: '2/16/16 12:16 PM' in jar file '/www/deploy/dev/MACHINE1/AccountMergeDEV_2015-08-06_14-33-47.jar'
Last edited: '8/3/15 3:42 PM'
UUID: '7cda53b2-5201-0000-0080-9c722b3eca55'
Start mode: 'Maintained'
Long description: ''
User-defined property names:
  'AlertEmailList' = 'authenticationalerts@hotmail.com'
  'ApplicationSupportGroup' = 'Integration'
  'EVENTTYPE' = 'Integration_ResponseSent'
  'LogLevel' = 'ERROR'
  'LoggingProgramName' = 'MergeRequest'
  'MaxPerInterval' = '5'
  'NotificationInterval' = '300'
Keywords:

--------
Mess1289I: Message 'com.authentication.ForgotUserNameEmail' on jvm 'MACHINE1' is stopped.

Additional thread instances: '0'
Deployed: '2/16/16 12:16 PM' in jar file '/www/deploy/dev/MACHINE1/ForgotUsernameEmailDEV_2012-10-23_03-45-49.jar'
Last edited: '10/23/12 2:15 PM'
UUID: '1d7154b2-5201-0000-0080-9c722b3eca55'
Start mode: 'Maintained'
Long description: ''
User-defined property names:
  'EmailFromAddress' = 'do-not-reply@hotmail.com'
  'EmailSubject' = 'Retrieved User Name'
Keywords:

--------
Mess1288I: Message 'com.authentication.PasswordService' on jvm 'MACHINE1' is running.

Additional thread instances: '0'
Deployed: '2/16/16 12:16 PM' in jar file '/www/deploy/dev/MACHINE1/PasswordServicesDEV_2014-11-04_03-51-52.jar'
Last edited: '11/4/14 3:20 PM'
UUID: 'd9b154b2-5201-0000-0080-9c722b3eca55'
Start mode: 'Maintained'
Long description: ''
User-defined property names:
  'ApplicationSupportGroup' = 'Integration'
  'EVENTTYPE' = 'Integration_RequestSent'
  'LoggingProgramName' = 'PasswordService'

Keywords:

--------
Mess1288I: Message 'com.authentication.RegistrationEmail' on jvm 'MACHINE1' is running.

Additional thread instances: '0'
Deployed: '2/16/16 12:17 PM' in jar file '/www/deploy/dev/MACHINE1/RegistrationEmailDEV_2012-07-31_16-44-48.jar'
Last edited: '7/31/12 4:43 PM'
UUID: 'c3d154b2-5201-0000-0080-9c722b3eca55'
Start mode: 'Maintained'
Long description: ''
User-defined property names:
  'AlertEmailList' = 'authenticationalerts@hotmail.com'
  'FromEmailAddress' = 'do-not-reply@hotmail.com'
  'LogLevel' = 'ERROR'
  'MaxPerInterval' = '5'
  'NotificationInterval' = '300'
Keywords:

--------
Mess1288I: Message 'com.authentication.RegistrationService' on jvm 'MACHINE1' is running.

Additional thread instances: '4'
Deployed: '2/16/16 12:17 PM' in jar file '/www/deploy/dev/MACHINE1/RegistrationServiceDEV_2015-10-29_05-29-56.jar'
Last edited: '10/29/15 3:55 PM'
UUID: '16f454b2-5201-0000-0080-9c722b3eca55'
Start mode: 'Maintained'
Long description: ''
User-defined property names:
  'ApplicationSupportGroup' = 'Integration'
  'EVENTTYPE' = 'Integration_RequestSent'
  'LoggingProgramName' = 'RegistrationService'

Keywords:

--------
Mess1288I: Message 'com.authentication.UserManagementService' on jvm 'MACHINE1' is running.

Additional thread instances: '4'
Deployed: '2/16/16 12:18 PM' in jar file '/www/deploy/dev/MACHINE1/UserManagementServiceDEV_2015-08-12_05-40-30.jar'
Last edited: '8/12/15 4:06 PM'
UUID: 'a1e455b2-5201-0000-0080-9c722b3eca55'
Start mode: 'Maintained'
Long description: ''
User-defined property names:
  'ApplicationSupportGroup' = 'Integration'
  'EVENTTYPE' = 'Integration_RequestSent'
  'LoggingProgramName' = 'UserManagementService'

Keywords:

--------
Mess1290I: File 'Java_Utility.jar' is deployed to jvm 'MACHINE1'.

Deployed: '2/16/16 12:14 PM' in jar file '/www/deploy/dev/MACHINE1/JDEPCISInternalDEV_2012-03-01_11-56-03.jar'
Last edited: '3/1/12 11:22 PM'
Keywords:

我想要获得的输出是文本文件中有AlertEmailList的地方。

Machine1,/www/deploy/dev/MACHINE1/AccountMergeDEV_2015-08-06_14-33-47.jar,com.authentication.MergeReply,authenticationalerts@hotmail.com
Machine1,/www/deploy/dev/MACHINE1/AccountMergeDEV_2015-08-06_14-33-47.jar,com.authentication.Eligibility,authenticationalerts@hotmail.com
Machine1,/www/deploy/dev/MACHINE1/AccountMergeDEV_2015-08-06_14-33-47.jar,com.authentication.MergeRequest,authenticationalerts@hotmail.com
Machine1,/www/deploy/dev/MACHINE1/RegistrationEmailDEV_2012-07-31_16-44-48.jar,com.authentication.RegistrationEmail,authenticationalerts@hotmail.com

我已经能够使用awk

获取状态输出
cat jvmdeets.txt|sed -n '/Mess129/q;p'|awk -v OFS=, -v r="^'|'$" '/Mess1288I|Mess1289I/ { o=$4; j=$8; s=$NF; gsub(r,"",o); gsub(r,"",j); sub(/\.$/,"",s) } /^Deployed:/ { p=$NF; gsub(r,"",p); print j, p, o, s }'|sort|uniq

但我无法通过在我的awk语句中用AlertEmailList替换Deployed:来获取电子邮件列表。

我试图至少收到电子邮件lisit

cat jvmdeets.txt|awk -v OFS=, -v r="^'|'$" '/Mess1288I|Mess1289I/ { o=$4; j=$8; gsub(r,"",o); gsub(r,"",j) } /^AlertEmailList/ { p=$NF; print p }'

我做错了什么?

1 个答案:

答案 0 :(得分:1)

请注意,您正在使用行锚^的开头查看,但该值是空格填充并引用

$ awk '/^AlertEmailList/' file

将不会返回任何内容

  $ awk '/AlertEmailList/' file
  'AlertEmailList' = 'authenticationalerts@hotmail.com'
  'AlertEmailList' = 'authenticationalerts@hotmail.com'
  'AlertEmailList' = 'authenticationalerts@hotmail.com'
  'AlertEmailList' = 'authenticationalerts@hotmail.com'

将返回行。