user3673211
user3673211

Reputation: 1

adding new line to an output file

I'm writing a script for comparing 2 variable in 2 line then output the line with equal value to new file. However, the new file only contain last line only, the earlier line was delete. I do google my problem but still not find the way out. Sorry for my English. Thank you very much in advance.

Here is my script somehow look like:

for (tmp1 = 1 ; tmp1 <= cnt1 ; tmp1++) {

  $line1 = `head -tmp1 file1| tail -1`;
  @str1 = split(/\s/, $line1);

  for (tmp2 = 1 ; tmp2 <= cnt2 ; tmp2++) {

    $line2 = `head -tmp2 file2| tail -1`;
    @str2 = split(/\s/, $line2);

    open(OUT, ">out");
    if ($str1[3] eq $str2[3]) {
      print OUT "$line1";
    }
  }
}

Upvotes: 0

Views: 51

Answers (1)

Jens
Jens

Reputation: 69440

You should open the before the loop starts, or use open (OUT, ">>out"); to append mode.

Upvotes: 1

Related Questions