Monday, February 1, 2010

Perl Script to Read and Print N Characters from a File

In the below sample script, i am reading and printing first 60 characters from each line/record


open(IN,"
open(OUT,">output");
while ()
{
     $st=$_;
     if($st =~ /^(.{60}) +\n/si)
    {
           print OUT "$1\n";
    }
    else
    {
         print OUT $st;
    }
}
close(output)
close(input)

0 comments:

Post a Comment

Recent Comments

About This Blog

Blog Archive

  © Blogger template Webnolia by Ourblogtemplates.com 2009

Back to TOP