Re: Adding a line in a file inside many directories
- From: krahnj@xxxxxxxxx (John W. Krahn)
- Date: Fri, 29 Jun 2007 17:38:54 -0700
usenet@xxxxxxxxxxxxxxx wrote:
On Jun 28, 12:00 pm, vedpsi...@xxxxxxxxx (Ved) wrote:Now I have to print a single line at say line number 20 in each of 150
number of kat.s file.
Hey, another chance to show off my favorite Perl module, IO::All.
Situation is bit complex (atleast for a beginer like me).
Actually it is so simple (with IO::All) that you're gonna think I'm
pulling your leg...
#!/usr/bin/perl
use strict;
use warnings;
use IO::All;
my $dir = '/tmp/clpm'; #root directory of data
my $line = 19; #print line 20 (first line is line zero)
my $file = 'kat.s'; #match this filename
map {print "@$_[$line]\n"}
io($dir)->filter(sub{$_->filename eq $file})->all_files(0);
Instead of using map in a void context:
print "@$_[$line]\n" for
io($dir)->filter(sub{$_->filename eq $file})->all_files(0);
Or just call print once with a large list:
print map "@$_[$line]\n",
io($dir)->filter(sub{$_->filename eq $file})->all_files(0);
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
.
- References:
- Prev by Date: Re: how to get references from imbricated capturing parenthesis ?
- Next by Date: Re: how to get references from imbricated capturing parenthesis ?
- Previous by thread: Re: Adding a line in a file inside many directories
- Next by thread: Adding a line in a file inside many directories
- Index(es):
Relevant Pages
|