Hi,
I can suggest an algo
1) read a file into an array : file - @array
2) @array = grep defined, @array (this removes all the blank values from an
@array)
3) write array again back to file
kind regards,
Kuldeep
On Mon, Oct 1, 2012 at 2:04 PM, Irfan Sayed irfan_sayed2...@yahoo.comwrote:
hi,
Hi Irfan,
On Mon, 1 Oct 2012 01:34:51 -0700 (PDT)
Irfan Sayed irfan_sayed2...@yahoo.com wrote:
hi,
i need to delete all blank lines from the text file
How do you define a blank line? Is it an empty line? Is it a line that contains
only
whitespace?
In any case, here are a few comments
thanks a lot !
will improve the coding standard.
regards,
irfan
From: Shlomi Fish shlo...@shlomifish.org
To: Irfan Sayed irfan_sayed2...@yahoo.com
Cc: Perl Beginners beginners@perl.org
Sent: Monday, October 1, 2012 4:08 PM
Subject: Re: delete blank lines
On Mon, Oct 1, 2012 at 3:34 AM, Irfan Sayed irfan_sayed2...@yahoo.com wrote:
hi,
i need to delete all blank lines from the text file
I usually just skip the blank lines when I read the data one line at a
time. Then you can print to a new file.
My example is below:
#!/usr/bin/perl
use
On Oct 20, Rose, Jeff said:
Basically what I am trying to do here is parse through an email file
grab the the basics, from/to/subject put those in a small text tab
separated database in the format of
File NumRecipients From FromIP Subject Spam-Status
and then pass the contents along to
-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Tuesday, August 31, 2004 6:50 AM
To: [EMAIL PROTECTED]
Subject: delete all lines in a file save it come out
Hi ,
I have a problem in deleting all the lines in a file and saving it .
Actually my log file keep
Hi ,
I have a problem in deleting all the lines in a file and saving it .
Actually my log file keep appending all the messages for that
i need to clean it up i.e delete all lines in it save it .
when i do this initially file shows zero bytes , but as soon
as the next message appends ,,
On Aug 31, [EMAIL PROTECTED] said:
open(FILE, $logfile) or die Couldn't open $logfile : $!\n; # This
logfile keeps appending in a linux m/c
flock(FILE,2);
while (sysread FILE, $buffer, 4096) {
$lines += ($buffer =~ tr/\n//);
}
This makes NO
On Aug 31, [EMAIL PROTECTED] said:
Well if all you want to do is count the number of lines in the file then
zero out the file, the easiest way that I can think of would be to use a
couple of system calls like this.
No, there is no reason to make any system calls at all.
open FILE, $file or
On Aug 31, Jim said:
open (FILE, +, $file) or die cannot open $file: $!;
I think you want + there, or else it will overwrite the contents of
the file and you won't be able to determine how many lines there were
originally.
flock (FILE, 2) or die cannot flock $file: $!;
For safety's sake, use
On Aug 31, Jim said:
open (FILE, +, $file) or die cannot open $file: $!;
I think you want + there, or else it will overwrite the
contents of the file and you won't be able to determine how
many lines there were originally.
Thanks. I was not sure what he was trying to do.
Sudhindra K S wrote:
Hi
Hello,
I am new to perl and getting confused with pattern matching.
How do i remove blank files from a file. For ex: i have a file as below
abc
xyz
def
123
Now i want to remove all blank lines and have an output as below
abc
xyz
def
123
How do i
Thanks
But the output is printed on the STDOUT. What if i want to get each of the lines
beginning with all: and put in a file or array? How do i do this?
Regards
Sudhindra
On Wed, 09 Jun 2004 John W. Krahn wrote :
Sudhindra K S wrote:
Hi
Hello,
I am new to perl and getting confused
Hi
I am getting this error message on using the command specified by you.
Unrecognized file test: -i at change.pl line 28.
Regards
Sudhindra
On Wed, 09 Jun 2004 John W. Krahn wrote :
Sudhindra K S wrote:
Hi
Hello,
I am new to perl and getting confused with pattern matching.
How
On Mon, 28 Oct 2002 13:54:28 -0500, [EMAIL PROTECTED] (Nikola
Janceski) wrote:
without using 'tail' how can I get the trailing 5 lines of a large file
quickly, without loading it all to memory?
is there anyway without pop and shifting through an array foreach line? (=
this is the only way I
On Tue, 29 Oct 2002, zentara wrote:
On Mon, 28 Oct 2002 13:54:28 -0500, [EMAIL PROTECTED] (Nikola
Janceski) wrote:
without using 'tail' how can I get the trailing 5 lines of a large file
quickly, without loading it all to memory?
is there anyway without pop and shifting through an
Nikola Janceski wrote:
without using 'tail' how can I get the trailing 5 lines of a large file
quickly, without loading it all to memory?
is there anyway without pop and shifting through an array foreach line?
(= this is the only way I could think of doing it)
with a little seek and
without using 'tail' how can I get the trailing 5 lines of a
large file
quickly, without loading it all to memory?
is there anyway without pop and shifting through an array
foreach line? (=
somebody posted this code last week, which gets the last line of the file
--
open F, file.txt
There is another one from perl monks, that may be easier:
this one is good for fixed length records in a data file or you can adapt
this
to search for \n as well, like the other
# gets last 100 bytes of the file
if (open (FH, file))
{
seek FH, -100, 2;
while (FH)
{
print $_;
}
close
Nikola Janceski wrote:
without using 'tail' how can I get the trailing 5 lines of a large file
quickly, without loading it all to memory?
is there anyway without pop and shifting through an array foreach line? (=
this is the only way I could think of doing it)
Hi,
This example should be good for your memory:
---
#!/usr/bin/perl -w
open(FILE, yourbigfile.txt) or die $!;
my @last5;
while (FILE) {
push @last5, $_;
shift @last5 if @last5 5;
}
print @last5;
Inspired by Beginning Perl - Wrox.
Regards,
Jostein
-Original Message-
From: Shishir K. Singh [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, June 18, 2002 11:47 AM
To: [EMAIL PROTECTED]
Subject: No of lines in a file
Hi,
Is there a way to get the number of lines in a file. Conditions:
a) Without using backticks on wc -l
b)
Uh oh!! Thanks !! Guess I will have to do it the old fashioned way!!
-Original Message-
From: Bob Showalter [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, June 18, 2002 11:51 AM
To: Shishir K. Singh; [EMAIL PROTECTED]
Subject: RE: No of lines in a file
-Original Message-
From:
from the cookbook:
$count += tr/\n/\n/ while sysread(FILE, $_, 2 ** 16);
-Original Message-
From: Shishir K. Singh [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, June 18, 2002 11:47 AM
To: [EMAIL PROTECTED]
Subject: No of lines in a file
Hi,
Is there a way to get the number of
On Tuesday, June 18, 2002, at 08:46 , Shishir K. Singh wrote:
Is there a way to get the number of lines in a file. Conditions:
a) Without using backticks on wc -l
b) Without opening the file and looping over the records
not really unless your OS provides some sort of 'meta-data'
file that
Timothy == Timothy Johnson [EMAIL PROTECTED] writes:
Timothy Try this:
Timothy open(INFILE,myfile.txt);
Timothy open(OUTFILE,SSlines.txt);
Timothy while(INFILE){
Timothyunless($_ eq \n){ #blank lines probably have only a \n
Timothy print OUTFILE $_;
Timothy}
Timothy }
The
Timothy,
Thank you very much for the quick reply! It works great :-)
Brian
Timothy Johnson wrote:
Try this:
open(INFILE,myfile.txt);
open(OUTFILE,SSlines.txt);
while(INFILE){
unless($_ eq \n){ #blank lines probably have only a \n
print OUTFILE $_;
}
}
-Original
One way (probably not the most elegant)
set a flag variable to 0
my $flagv=0
foreach to read file
{
$flag=1 if (/^NC00/);
if ($flag)
{
store line
increment counter
if counter 5 $flag=0
}
--
Chris D. Garringer
LAN/WAN Supervisor
Toshiba International
713-466-0277
howabout
while (FILE) {
next unless /^NC00/;
push @required , $_;
}
On Fri, Nov 16, 2001 at 03:42:59PM -0500, [EMAIL PROTECTED] shaped the
electrons to read:
Hello All,
This appears to be quite simple, but yet the answer has eluded me.
I can/kow how to use a foreach loop
I am not sure exactly what you need help with in this question.
The appending can be handled by something like:
$line = qq[Open\n].$line.qq[\narbitary config setting 1\n\narbitrary
config setting 2\n\n];
Where $line already contains the line from the file.
Check this out for help with the
David Blevins wrote:
: There has to be a better way to modify/delete lines in a file than this.
Time for a one-liner:
perl -ni -e 'print unless /I'm a bad line, delete me\./' thefile
-n loops through the lines of thefile, but doesn't print them unless you ask
-i edits thefile in place
-e
On Thu, 24 May 2001, David Blevins wrote:
Thanks to everyone for the great input on my last question. Here's another.
There has to be a better way to modify/delete lines in a file than this.
my $filename = thefile;
my $lineToDelete = I'm a bad line, delete me.;
open(FILE,
So, as far as editing files in a subroutine of a script, there does not seem
to be an easier or more performant way?
Would it be performant to call the perl command as a subprocess, as in:
`perl -ni -e 'print unless /I'm a bad line, delete me\./' thefile`;
David
Timothy Kimball wrote:
On Thu, 24 May 2001, David Blevins wrote:
So, as far as editing files in a subroutine of a script, there does not seem
to be an easier or more performant way?
Would it be performant to call the perl command as a subprocess, as in:
`perl -ni -e 'print unless /I'm a bad line, delete me\./'
On May 24, David Blevins said:
So, as far as editing files in a subroutine of a script, there does not seem
to be an easier or more performant way?
Would it be performant to call the perl command as a subprocess, as in:
`perl -ni -e 'print unless /I'm a bad line, delete me\./' thefile`;
You
brahmanyam [EMAIL PROTECTED] wrote:
: Hi,
: Iam reading flat text file of 10 lines. Each line has got data of
: maximum 10 characters.
: I want to eliminate duplicate lines and blank lines out of that file.
: i.e. something like sort -u in unix.
:
: Got plenty of memory? =o)
:
: open
- Original Message -
From: Casey West [EMAIL PROTECTED]
To: M.W. Koskamp [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]; cherukuwada subrahmanyam [EMAIL PROTECTED];
[EMAIL PROTECTED]
Sent: Wednesday, May 02, 2001 6:45 PM
Subject: Re: eliminating duplicate lines in a file
On Wed, May 02, 2001
On Wed, May 02, 2001 at 11:11:20AM -0700, Paul wrote:
:
: --- M.W. Koskamp [EMAIL PROTECTED] wrote:
: : open FH, lines.txt || die $!;
: : my %uniq;
: : map{$uniq{$_}=1 and print $_ unless $uniq{$_} }FH;
:
: lol -- one better(ish):
: print map { $uniq{$_} ? '' : $uniq{$_}=$_ } FH;
38 matches
Mail list logo