FILE1.TXT如何連接Perl中兩個文件中的相應行?
hello
tom
well
FILE2.TXT
如何合併與FILE2.TXT FILE1.TXT;然後創建一個新文件 - file3.txt
hello world
tom jerry
well done
感謝您的閱讀和回覆。
附上根據答案完成的代碼。
#!/usr/bin/perl
use strict;
use warnings;
open(F1,"<","1.txt") or die "Cannot open file1:$!\n";
open(F2,"<","2.txt") or die "Cannot open file2:$!\n";
open (MYFILE, '>>3.txt');
while(<F1>){
chomp;
chomp(my $f2=<F2>);
print MYFILE $_ . $f2 ."\n";
}
是否必須是Perl或者也可以是Linux呢?你可以做$ paste file1.txt file2.txt – MJB 2010-04-15 13:52:29
Dup:http://stackoverflow.com/questions/1636755/how-many-different-ways-are-there-to-concatenate-two-files-line-by- line-using-per/1636981#1636981 – FMc 2010-04-15 14:04:31
使用Perl和WinXP。 $貼?這是來自Linux的命令嗎? – 2010-04-15 14:05:36