我有一个txt文件,其中提供了大量信息。 我想阅读并存储“状态”部分。
示例:
id........username...... status......language .......image
11111 abcdefg Man Utd won for the second time ENG img1244
11112 abcdaaa Man Utd won for the third time ENG img1245
11113 abcdbbb Man Utd won for the fourth time ENG img1246
11114 abcdccc Man Utd won for the fifth time ENG img1247
11115 abcdddd Man Utd won for the sixth time ENG img1248
And what I should obtain is the following
Man Utd won for the second time
Man Utd won for the third time
Man Utd won for the fourth time
Man Utd won for the fifth time
Man Utd won for the sixth time
我想要做的是将用户名中的字符串数据存储到“ENG”字符串。
感谢您的帮助。
答案 0 :(得分:0)
您可以使用简单的perl脚本执行此操作。对于Windows,可以从activestate下载perl。 Linux通常已经安装了perl。
使用:
该脚本假定:
剧本:
使用严格;
unless(open(INFILE, "input.txt")){
print "Unable to open input file input.txt for reading, possible reason: $!\n";
exit;
};
unless(open(OUTFILE, ">output.txt")){
print "Unable to open output file output.txt for writing, possible reason: $!\n";
exit;
};
my $x = 1;
foreach my $line (<INFILE>){
print "$line";
if($line =~ /((?:Wom|M)an.*) ENG/){
print OUTFILE $1."\n";
}else{
print "No match found on line $x\n";
}
$x++;
}
close(INFILE);
close(OUTFILE);
exit;