I have a sample.txt file placed in directory say /output_files with some content in it.
I want to create a new file say sample_new.txt and add the contents of sample.txt multiple times based on some condition.
For example:
- Create new file
sample_new.txt - For condition <1..3>
- Add the content of
sample.txtintosample_new.txtfiles 3 times as the loop will run 3 times.
I tried with below script, but it doesn't work:
my $sample_file = "/output_files/sample.txt";
my $new_sample_file = "/output_files/sample_new.txt";
#For loop --running say 3 times
open my $IN, '<', $sample_file or die $!;
open my $OUT, '>>', $new_sample_file or die $!;
while (<$IN>) {
s/\b(hld_cf_id)\b/1234/g; #replacing some content while writing
print {$OUT} $_;
}
close $OUT or die $!;
#close loop;