简体   繁体   English

从脚本中提取邮件ID

[英]Extract mail id from Script

Use this shell script as source to extract mail id fields . 使用此Shell脚本作为源来提取邮件ID字段。 Need to extract the mail ids alone. 需要单独提取邮件ID。 For example need to take anupam.panda@btx.com ajay.k.singh@btx.com Please advice. 例如需要采取anupam.panda@btx.com ajay.k.singh@btx.com请咨询。

#!/bin/ksh
#exit 0
export nodename=`uname -n`
export SENDER_ID=BTFON.$nodename@btx.com
mailx -s "ERROR: OWB loading for ${FILE_NAME} has failed " anupam.panda@btx.com,ajay.k.singh@btx.com <<EOF

If directory to scan (recursively) is MYDIR then: 如果要扫描的目录(递归)是MYDIR,则:

grep -hrioI '[a-z0-9_\.]\+@[a-z0-9]\+\.[a-z0-9\.]\{2,\}' MYDIR 2>/dev/null | sort -u

If you only want to scan shell scripts add --include=*.sh option: 如果只想扫描shell脚本,请添加--include = *。sh选项:

grep -hrioI --include=*.sh '[a-z0-9_\.]\+@[a-z0-9]\+\.[a-z0-9\.]\{2,\}' MYDIR 2>/dev/null | sort -u

EDIT I have changed the pattern for TLD to be at least 2 symbols ({2,} instead of +). 编辑我已将TLD的模式更改为至少2个符号({2,}而不是+)。

awk -v FS="[\",<]" '/mailx/{for(i=3;i<NF;i++) print $i}' file

If your files have similar formatting and you wish to extract all emails which follow the subject line until < 如果文件格式相似,并且您希望提取所有主题行之后的电子邮件,直到<

To capture sender_id then do something like this - 要捕获sender_id,请执行以下操作-

awk -v FS="[\",<$]" '
/mailx/{print "RECEPIENTS: ";for(i=4;i<NF;i++) print $i;next}
/SENDER_ID/{print "SENDER INFO: \n"$NF}' file

Test: 测试:

[jaypal:~/Temp] awk -v FS="[\",<$]" '
/mailx/{print "RECEPIENTS: ";for(i=4;i<NF;i++) print $i;next}
/SENDER_ID/{print "SENDER INFO: \n"$NF}' file
SENDER INFO: 
nodename@btx.com
RECEPIENTS: 
 anupam.panda@btx.com
ajay.k.singh@btx.com 

Try: 尝试:

Code: 码:

awk -F\" '
    /^mailx/{
        n=split(substr($3,2,length($3)-6),emails,/,/)
        for (i=1;i<=n;i++)print emails[i]}
    ' f3

Output: 输出:

anupam.panda@btx.com
ajay.k.singh@btx.com

This might work for you: 这可能对您有用:

sed '/^mailx/!d;s/.*"\s*\|\s*\S*$//g;y/,/\n/' file1 file2 file3 ...
anupam.panda@btx.com
ajay.k.singh@btx.com

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM