Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何解析电子邮件文本(bash)_Bash_Email_Mime_Quoted Printable - Fatal编程技术网

如何解析电子邮件文本(bash)

如何解析电子邮件文本(bash),bash,email,mime,quoted-printable,Bash,Email,Mime,Quoted Printable,我有以下文字(通过电子邮件收到): 如何使用“bash”提取这些信息?好的,我来咬一口。数据是可打印的,我们需要纯文本版本。所以让我们使用Perl,它已经有了这方面的代码 #!/usr/bin/perl use strict; use PerlIO::via::QuotedPrint; # Open input file through quoted-printable filter $ARGV[0] ne "" or die "No file specified"; open(IN

我有以下文字(通过电子邮件收到):


如何使用“bash”提取这些信息?

好的,我来咬一口。数据是可打印的,我们需要纯文本版本。所以让我们使用Perl,它已经有了这方面的代码

#!/usr/bin/perl

use strict;
use PerlIO::via::QuotedPrint;

# Open input file through quoted-printable filter    
$ARGV[0] ne "" or die "No file specified";
open(IN, '<:via(QuotedPrint)', $ARGV[0]) or die "Could not open file";

# needles to search in the haystack.
my @needles = ( 'Name',
                'Email Address',
                'Telephone',
                'Comments',
                'Reference',
                'Your Ref',
                'View Property' );

my $line;
my $key = "";

# handle the file linewise.
foreach $line (<IN>) {

    # The data we want is always one line after the
    # key line, so:

    # If we remember a key
    if($key ne "") {
        # print key and line, reset key variable.
        print "$key =$line";
        $key = "";
    } else {
        # otherwise, see if we find a key in the current line.
        # If so, remember it so that the data in the next line
        # will be printed.
        my $n;
        foreach $n (@needles) {
            if(index($line, $n) != -1) {
                $key = $n;
                last;
            }
        }
    }
}
#/usr/bin/perl
严格使用;
使用PerlIO::via::QuotedPrint;
#通过引用的可打印过滤器打开输入文件
$ARGV[0]ne“”或“未指定文件”;

打开(在“中),好的,我会咬一口。数据引用为可打印的,我们需要纯文本版本。所以让我们使用Perl,它已经有了这方面的代码

#!/usr/bin/perl

use strict;
use PerlIO::via::QuotedPrint;

# Open input file through quoted-printable filter    
$ARGV[0] ne "" or die "No file specified";
open(IN, '<:via(QuotedPrint)', $ARGV[0]) or die "Could not open file";

# needles to search in the haystack.
my @needles = ( 'Name',
                'Email Address',
                'Telephone',
                'Comments',
                'Reference',
                'Your Ref',
                'View Property' );

my $line;
my $key = "";

# handle the file linewise.
foreach $line (<IN>) {

    # The data we want is always one line after the
    # key line, so:

    # If we remember a key
    if($key ne "") {
        # print key and line, reset key variable.
        print "$key =$line";
        $key = "";
    } else {
        # otherwise, see if we find a key in the current line.
        # If so, remember it so that the data in the next line
        # will be printed.
        my $n;
        foreach $n (@needles) {
            if(index($line, $n) != -1) {
                $key = $n;
                last;
            }
        }
    }
}
!/usr/bin/perl
严格使用;
使用PerlIO::via::QuotedPrint;
#通过引用的可打印过滤器打开输入文件
$ARGV[0]ne“”或“未指定文件”;

首先,感谢大家的帮助

我已经找到了另一种方法来做到这一点,我想把它张贴在这里

sed -e 's/=C2=A0/ /g' abc.txt | perl -pe 'use MIME::QuotedPrint; $_=MIME::QuotedPrint::decode($_);' | grep "^Interested in:" | cut  -d' ' -f3-

sed -e 's/=C2=A0/ /g' abc.txt | perl -pe 'use MIME::QuotedPrint; $_=MIME::QuotedPrint::decode($_);' | grep "^Name:" | cut  -d' ' -f2-
我不知道为什么,但原始文本中包含“=C2=A0”,似乎与“.相同,所以我只使用“sed”将它们去掉

致以最良好的祝愿


尼尔。

首先,感谢大家的帮助

我已经找到了另一种方法来做到这一点,我想把它张贴在这里

sed -e 's/=C2=A0/ /g' abc.txt | perl -pe 'use MIME::QuotedPrint; $_=MIME::QuotedPrint::decode($_);' | grep "^Interested in:" | cut  -d' ' -f3-

sed -e 's/=C2=A0/ /g' abc.txt | perl -pe 'use MIME::QuotedPrint; $_=MIME::QuotedPrint::decode($_);' | grep "^Name:" | cut  -d' ' -f2-
我不知道为什么,但原始文本中包含“=C2=A0”,似乎与“.相同,所以我只使用“sed”将它们去掉

致以最良好的祝愿


尼尔。

你尝试过什么?我不会使用
bash
。我会使用脚本语言,比如
perl
awk
…我尝试过awk,但我就是无法让它工作!也许你可以展示你尝试过的东西,你可以得到帮助。“你不能将这些de=tails传递给任何第三方。”在Stackoverflow上看到这是一件好事。:PI更改了文本!详细信息不在上面发布的文本中!您尝试了什么?我不会使用
bash
。我会使用脚本语言,如
perl
awk
…我尝试了awk,但我就是无法让它工作!也许您可以展示您尝试过的内容,然后您可以使用它您不能将这些详细信息传递给任何第三方在Stackoverflow上看到这是一件好事。PI更改了文本!详细信息不在上面发布的文本中!做得很好。看起来每行最多需要一个键,所以可能在
$key=$p
之后放置一个
,以便在找到键后终止循环。最后,一个诡辩(实际上就是这样):“模式”建议使用正则表达式(或globbing模式),但您正在搜索字符串文字(您在查找匹配项时将其命名为“key”)。
last;
是一个很好的观点;我不知道为什么我一开始就忽略了它。至于模式,让我们使用针(如在大海捞针中发现的)。针(如果您愿意的话),感谢您的更新。@Neillardon:为了回答者和未来读者的利益:如果答案解决了您的问题,请单击旁边的大复选标记接受它;如果您觉得它至少有帮助,请单击向上箭头图标向上投票。做得很好。看起来每行最多需要一个键,所以可能要加一个
last;
$key=$p
之后,一旦找到一个键,就终止循环。最后,一个诡辩(实际上就是这样):“pattern”表示正则表达式(或globbing模式),但您正在搜索字符串文本(在找到匹配项时,您将其命名为“key”).最后一个;
是一个很好的观点;我不知道为什么我一开始就把它漏掉了。至于图案,让我们用针(在干草堆里找到的)。要说的是针(如果你愿意的话),感谢您的更新。@Neillardon:为了回答者和未来读者的利益:如果某个答案解决了您的问题,请单击旁边的大复选标记接受它;如果您觉得它至少有帮助,请单击向上箭头图标向上投票。