Thursday, October 09, 2008

how to remove blank lines in a file with perl

I found one way to get it work.

The text file (rsp3.txt):
-----
(blank)
(blank)
p2_xe_1996-02-16.rsp
p2_xe_1996-03-08.rsp
p2_xe_1996-04-18.rsp
(blank)
(blank)
p2_xe_1996-05-20.rsp
p2_xe_1996-06-20.rsp
p2_xe_1996-06-20.rsp
------------------------

script:


#!/usr/bin/perl -w


$response_file=`cat rsp3.txt`;

$length1=length($response_file);



print "$response_file";

print "$length1\n";

$response_file=~s/^\n//gm;
print "$response_file";

$length2=length($response_file);
print "$length2\n";

No comments: