http://www.perlmonks.org?node_id=965035


in reply to Re: replacing text in multiple files
in thread replacing text in multiple files

cat *.log | your_script > modified.log-data

Why use cat when Perl can do it all by itself?  With the added benefit of $ARGV letting you know which file you're working on, and being able to do in-place edits via -i / $^I:

$ cat *.log bar1 bar2 bar3 baz1 baz2 baz3 foo1 foo2 foo3 $ perl -ne 'print "$ARGV: $_"' *.log bar.log: bar1 bar.log: bar2 bar.log: bar3 baz.log: baz1 baz.log: baz2 baz.log: baz3 foo.log: foo1 foo.log: foo2 foo.log: foo3 $ cat *.log | perl -ne 'print "$ARGV: $_"' -: bar1 -: bar2 -: bar3 -: baz1 -: baz2 -: baz3 -: foo1 -: foo2 -: foo3 $ perl -i -ne 'print ucfirst $_' *.log $ cat *.log Bar1 Bar2 Bar3 Baz1 Baz2 Baz3 Foo1 Foo2 Foo3

(note to the OP:  -n is the short "command line" version of saying while (<>) { ... } — see perl -h )