开发者

What is written in one file write to another

开发者 https://www.devze.com 2023-01-06 22:22 出处:网络
I have one file, and I need everything that is written in some time frame to that file to be written to a second file.

I have one file, and I need everything that is written in some time frame to that file to be written to a second file.

What is the best way to do so? Open some thread that开发者_JAVA技巧 will read the file and do so ?

Any ideas ?


The tee utility might be what you're looking for:

#! /usr/bin/perl

use warnings;
use strict;

my @files = qw/ file1 file2 /;

open my $fh, "| tee @files >/dev/null"
  or die "$0: start tee failed: $!";

print $fh "$_\n" for map int rand 10, 1 .. 5;

close $fh or warn "$0: close tee: $!";

Sample run:

$ ./write-both

$ cat file1
0
7
5
8
2

$ cat file2
0
7
5
8
2


Sounds like a job for tail -f or the poor man's tail -f emulation.


Sounds like a job for File::Copy

0

精彩评论

暂无评论...
验证码 换一张
取 消