我有一个文件 a.txt,我有一个文件 b.txt。我正在阅读这两个文件。
让我们假设 a.txt 有:
Apple is a fruit.
I like java.
I am an human being.
I am saying hello world.
可以说 b.txt 有
I am the planet earth
现在我正在尝试在 a.txt 中搜索特定字符串,例如:我是人类。如果我找到这一行。我想将 b.txt 中的内容附加到 a.txt。我的输出文件应该看起来像这样
Apple is a fruit.
I like java.
I am the planet earth---->appended
I am an human being.
I am saying hello world.
我在下面尝试,但没有帮助
open (FILE1 , "a.txt")
my (@fpointer1) = <FILE>;
close FILE1
open (FILE2 , "b.txt")
my (@fpointer1) = <FILE>;
close FILE2
#Open the a.txt again, but this time in write mode
open (FILE3 , ">a.txt")
my (@fpointer1) = <FILE>;
close FILE3
foreach $line (@fpointer1) {
if (line to be searched is found)
--> Paste(Insert) the contents of file "b.txt" read through fpointer2
}