delete blank lines from text file

2012-10-01 Thread Irfan Sayed
hi, i need to delete all blank lines from the text file wrote following code. however, all the blank lines are not getting deleted. please suggest open FILE,+, 'C:\Users\bvcontrolbuild\Desktop\test.txt';  while (FILE)    {     chomp;     push (@lines, $_\n);    }   close

Re: delete blank lines from text file

2012-10-01 Thread Kuldeep Dhole
, i need to delete all blank lines from the text file wrote following code. however, all the blank lines are not getting deleted. please suggest open FILE,+, 'C:\Users\bvcontrolbuild\Desktop\test.txt'; while (FILE) { chomp; push (@lines, $_\n); } close

Re: delete blank lines from text file

2012-10-01 Thread Shlomi Fish
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

Re: delete blank lines from text file

2012-10-01 Thread Irfan Sayed
from text file 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

Re: delete blank lines from text file

2012-10-01 Thread Chris Stinemetz
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 5.010

Re: Deleting last 10 lines of a file

2010-03-24 Thread sheela b
Thanks a lot Shlomi and Thomas. I will try with these methods. On Tue, Mar 23, 2010 at 7:13 PM, Shlomi Fish shlo...@iglu.org.il wrote: Hi Sheela, On Tuesday 23 Mar 2010 15:06:24 sheela b wrote: Hi All, How to delete last 10 lines of a file using Perl one liner? I used

Deleting last 10 lines of a file

2010-03-23 Thread sheela b
Hi All, How to delete last 10 lines of a file using Perl one liner? I used the following one liner to delete first 10 lines of a file, perl -i.bak -ne 'print unless 1..10' test.txt Regards Sheela

AW: Deleting last 10 lines of a file

2010-03-23 Thread Thomas Bätzler
sheela b sheela.b.2...@gmail.com asked: How to delete last 10 lines of a file using Perl one liner? I used the following one liner to delete first 10 lines of a file, perl -i.bak -ne 'print unless 1..10' test.txt OTTOH: perl -i.bak -ne 'BEGIN { $b[9]= } print shift @b; push @b

Re: Deleting last 10 lines of a file

2010-03-23 Thread Shlomi Fish
Hi Sheela, On Tuesday 23 Mar 2010 15:06:24 sheela b wrote: Hi All, How to delete last 10 lines of a file using Perl one liner? I used the following one liner to delete first 10 lines of a file, perl -i.bak -ne 'print unless 1..10' test.txt If it doesn't have to be a one-liner, you

Unable to finally commit the changes made to some lines in a file using Tie::file

2008-04-27 Thread [EMAIL PROTECTED]
$ITUNES_FILE_PATH = /cygdrive/d/MyDocuments/My Music/iTunes; my $ITUNES_LIBRARY_FILE_NAME = iTunes Music Library1.txt; my $ITUNES_LIBRARY_FILE = $ITUNES_FILE_PATH/ $ITUNES_LIBRARY_FILE_NAME; my $PREPEND_PLAYLIST_KEY = OEL: ; print $ITUNES_LIBRARY_FILE\n; tie my @lines, 'Tie::File', $ITUNES_LIBRARY_FILE_NAME

Re: Unable to finally commit the changes made to some lines in a file using Tie::file

2008-04-27 Thread John W. Krahn
); splice @charArray, 26, 0, $PREPEND_PLAYLIST_KEY; print @charArray\n; Nowhere do you modify $lines[$i] which means that you are not modifying the file itself. } } untie @lines; #close $ITUNES_LIBRARY_FILE; Please find the file I am trying to modify here: /dict

Re: Extreme beginner question on reading lines from a file.

2007-07-19 Thread [EMAIL PROTECTED]
On Jul 18, 6:16 am, [EMAIL PROTECTED] (Ayesha) wrote: Hi all I got started on Perl only today! I have a text file in which I need to read a line and the line after that. Like line1 and line2 line2 and line3 line3 and line4 when I use while($line1 = MYFILE){

Re: Extreme beginner question on reading lines from a file.

2007-07-19 Thread Chas Owens
On 7/19/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: On Jul 18, 6:16 am, [EMAIL PROTECTED] (Ayesha) wrote: Hi all I got started on Perl only today! I have a text file in which I need to read a line and the line after that. Like line1 and line2 line2 and line3 line3 and line4 when I

Re: Extreme beginner question on reading lines from a file.

2007-07-19 Thread John W. Krahn
Chas Owens wrote: On 7/19/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: On Jul 18, 6:16 am, [EMAIL PROTECTED] (Ayesha) wrote: when I use while($line1 = MYFILE){ $line = MYFILE; } while ($line=FH) { print$line; } 2. while

Re: Extreme beginner question on reading lines from a file.

2007-07-19 Thread Chas Owens
On 7/19/07, John W. Krahn [EMAIL PROTECTED] wrote: Chas Owens wrote: On 7/19/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: On Jul 18, 6:16 am, [EMAIL PROTECTED] (Ayesha) wrote: when I use while($line1 = MYFILE){ $line = MYFILE; } while

Re: Extreme beginner question on reading lines from a file.

2007-07-19 Thread Ryan
What is a lexical file handle? I'm working my way through Ford's Perl Programming for the Absolute Beginner (2007) and Lee's Beginning Perl (2004), and they both use the FH style of file handle. Should I do differently? Thanks. --Chris Chas Owens wrote: On 7/19/07, [EMAIL PROTECTED]

Re: Extreme beginner question on reading lines from a file.

2007-07-19 Thread Chas Owens
On 7/19/07, Ryan [EMAIL PROTECTED] wrote: What is a lexical file handle? I'm working my way through Ford's Perl Programming for the Absolute Beginner (2007) and Lee's Beginning Perl (2004), and they both use the FH style of file handle. Should I do differently? snip Yes, you should use

Re: Extreme beginner question on reading lines from a file.

2007-07-19 Thread Jeff Pang
--- Ryan [EMAIL PROTECTED] wrote: What is a lexical file handle? I'm working my way through Ford's Perl Programming for the Absolute Beginner (2007) and Lee's Beginning Perl (2004), and they both use the FH style of file handle. From perl 5.6 you can say, open my $fh,test.txt or die

Extreme beginner question on reading lines from a file.

2007-07-18 Thread Ayesha
Hi all I got started on Perl only today! I have a text file in which I need to read a line and the line after that. Like line1 and line2 line2 and line3 line3 and line4 when I use while($line1 = MYFILE){ $line = MYFILE; } I get output line1 and

Re: Extreme beginner question on reading lines from a file.

2007-07-18 Thread Gary Stainburn
On Wednesday 18 July 2007 06:16, Ayesha wrote: Hi all I got started on Perl only today! I have a text file in which I need to read a line and the line after that. Like line1 and line2 line2 and line3 line3 and line4 when I use while($line1 = MYFILE){ $line =

Re: Extreme beginner question on reading lines from a file.

2007-07-18 Thread Jeff Pang
--- Ayesha [EMAIL PROTECTED] wrote: Hi all I got started on Perl only today! I have a text file in which I need to read a line and the line after that. Like line1 and line2 line2 and line3 line3 and line4 when I use while($line1 = MYFILE){ $line =

RE: Extreme beginner question on reading lines from a file.

2007-07-18 Thread Joseph L. Casale
learning, so I am not sure why I need to do more? Thanks! jlc -Original Message- From: Gary Stainburn [mailto:[EMAIL PROTECTED] Sent: Wednesday, July 18, 2007 10:15 AM To: beginners@perl.org Subject: Re: Extreme beginner question on reading lines from a file. On Wednesday 18 July 2007 17

Re: Extreme beginner question on reading lines from a file.

2007-07-18 Thread Gary Stainburn
On Wednesday 18 July 2007 17:08, Joseph L. Casale wrote: Is that true? I use while loops and they cycle through each line without me keeping track? jlc Yeah, it's true. Why would you want to keep track? (you can BTW, look at perldoc perlvar for $.) in my code, the 1st line is written into

Re: Extreme beginner question on reading lines from a file.

2007-07-18 Thread Chas Owens
On 7/18/07, Joseph L. Casale [EMAIL PROTECTED] wrote: Hrm, I am confused then:) I have this as a file I am using right now! while (FILEIN) { my @data = split; next unless @data == 3; next if grep (/[^0-9.-]/, @data); printf FILEOUT X%s Y%s\n, $data[0], $data[1];

Re: Extreme beginner question on reading lines from a file.

2007-07-18 Thread Rob Dixon
Chas Owens wrote: On 7/18/07, Joseph L. Casale [EMAIL PROTECTED] wrote: Hrm, I am confused then:) I have this as a file I am using right now! while (FILEIN) { my @data = split; next unless @data == 3; next if grep (/[^0-9.-]/, @data); printf FILEOUT X%s Y%s\n,

Re: consecutive lines in a file

2006-10-13 Thread Tom Phoenix
. @a1_s= split/\/, $_{$I]; @a2_s= split/\/,$_[$i+1]; I can't see what you're trying to do. It looks as if you're trying to do something with the @_ array. Is that right? Or maybe you're hoping that those expressions on the right will evaluate as consecutive lines from the file? Here's some untested

RE: consecutive lines in a file

2006-10-13 Thread Krishnakumar K P
-Original Message- From: Luba Pardo [mailto:[EMAIL PROTECTED] Sent: Friday, October 13, 2006 6:27 PM To: beginners@perl.org Subject: consecutive lines in a file Dear sir/madam: I am trying to write a script to process to consecutive lines at a time and compare elements of between two

Re: consecutive lines in a file

2006-10-13 Thread Mumia W.
On 10/13/2006 07:57 AM, Luba Pardo wrote: Dear sir/madam: I am trying to write a script to process to consecutive lines at a time and compare elements of between two consecutive lines. I don't understand this sentence. I tried something like: $i=0; while (IN){ chomp; @a1_s= split/\/,

Re: Removing specific lines from a File

2005-10-21 Thread Jeff 'japhy' Pinyan
to spamassassin pm to check the status but the email file contains these lines which mess with spamassassins filtering which I have to remove in order to get an accurate spam score(using the pm not the daemon don't ask me why :-)) P I 19-10-2005 21:35:00 [EMAIL PROTECTED] O T

Removing specific lines from a File

2005-10-20 Thread Rose, Jeff
Subject Spam-Status and then pass the contents along to spamassassin pm to check the status but the email file contains these lines which mess with spamassassins filtering which I have to remove in order to get an accurate spam score(using the pm not the daemon don't ask me why

Re: printing lines from a file

2005-02-26 Thread John W. Krahn
Christopher Spears wrote: Here is some code I am working on: #!/bin/perl -w use strict; my $number_of_args = @ARGV; open STDERR, ./caught_errors or die Can't create caught_errors: $!; if ($number_of_args == 0) { print Not enough arguments!\n; print Usage: ./cedit somefile.C++\n;

Re: What search string do I use on google or perldoc so that I know how to display a specified range of lines from a file (like sed -n 24, 48p filename)?

2004-10-23 Thread Zeus Odin
a specified range of lines from a file (like sed -n 24, 48p filename)? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response

Re: What search string do I use on google or perldoc so that I know how to display a specified range of lines from a file (like sed -n 24, 48p filename)?

2004-10-23 Thread Bob Showalter
Ken Wolcott wrote: A fishing pole question rather than a fish question :-) What search string do I use on google or perldoc so that I know how to display a specified range of lines from a file (like sed -n 24, 48p filename)? Zeus gave you the solution, but the background is explained in perldoc

What search string do I use on google or perldoc so that I know how to display a specified range of lines from a file (like sed -n 24, 48p filename)?

2004-10-22 Thread Ken Wolcott
A fishing pole question rather than a fish question :-) What search string do I use on google or perldoc so that I know how to display a specified range of lines from a file (like sed -n 24, 48p filename)? s2p no longer operates the way I used to use it back in perl 3x days :-) man s2p really

delete all lines in a file save it come out

2004-08-31 Thread Sudhakar . Gajjala
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 ,, file sizes

RE: delete all lines in a file save it come out

2004-08-31 Thread christopher . l . hood
-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

RE: delete all lines in a file save it come out

2004-08-31 Thread Jim
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

Re: delete all lines in a file save it come out

2004-08-31 Thread Jeff 'japhy' Pinyan
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

RE: delete all lines in a file save it come out

2004-08-31 Thread Jeff 'japhy' Pinyan
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

RE: delete all lines in a file save it come out

2004-08-31 Thread Jeff 'japhy' Pinyan
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

RE: delete all lines in a file save it come out

2004-08-31 Thread Jim
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.

RE: Merging lines in a file

2004-08-30 Thread Jan Eden
Hi, thanks for all the suggestions. I originally tried to avoid slurping the whole file into memory, but got stuck using the $. variable to address a line and the one following it. Thanks John and Gunnar for pointing me to the right direction, and thanks to Charles for his extensive comments.

Re: Merging lines in a file

2004-08-29 Thread Gunnar Hjalmarsson
Jan Eden wrote: I had the following task: Open a file, read it and merge all pairs of lines containing a certain number of tabs. Example: Blablabla abc cab bca 123 453 756 Blablabla Blablabla Here, lines 2 and three should be merged, while the other lines should remain untouched. Expected result:

Re: Merging lines in a file

2004-08-29 Thread John W. Krahn
Jan Eden wrote: Hi, Hello, I had the following task: Open a file, read it and merge all pairs of lines containing a certain number of tabs. Example: Blablabla abc cab bca 123 453 756 Blablabla Blablabla Here, lines 2 and three should be merged, while the other lines should remain untouched.

RE: Merging lines in a file

2004-08-29 Thread Charles K. Clarkson
Jan Eden [EMAIL PROTECTED] wrote: : I had the following task: Open a file, read it and merge all : pairs of lines containing a certain number of tabs. Example: : : Blablabla : abc cab bca : 123 453 756 : Blablabla : Blablabla : : Here, lines 2 and three should be merged, while the other : lines

Re: Merging lines in a file

2004-08-29 Thread John W. Krahn
Jan Eden wrote: Hi, Hello again, I had the following task: Open a file, read it and merge all pairs of lines containing a certain number of tabs. Example: Blablabla abc cab bca 123 453 756 Blablabla Blablabla Here, lines 2 and three should be merged, while the other lines should remain

Perl oneliner to delete lines from a file

2004-08-09 Thread Ramprasad A Padmanabhan
I want to write a command line perl 'script' to delete one or more lines from a file , by line number for eg in sed I can do the same in two steps cat FILENAME | sed -e '1,10d' FILENAME.TMP mv FILENAME.TMP FILENAME The above mechanism has a lot of pitfalls , like maintaining

Re: Perl oneliner to delete lines from a file

2004-08-09 Thread Jose Alves de Castro
On Mon, 2004-08-09 at 07:34, Ramprasad A Padmanabhan wrote: I want to write a command line perl 'script' to delete one or more lines from a file , by line number Hi :-) If I understand correctly, you want to delete lines X to Y from a file, right? perl -i -ne 'print unless 1..10' file

Re: Removing blank lines from a file

2004-06-09 Thread John W. Krahn
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

Re: Re: Removing blank lines from a file

2004-06-09 Thread sudhindra k s
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

Re: Re: Removing blank lines from a file

2004-06-09 Thread sudhindra k s
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

Re: CODING STYLE (was Re: Count the number of lines in a file without actually iterating through the file)

2004-02-29 Thread zsdc
WC -Sx- Jones wrote: zsdc wrote: WC -Sx- Jones wrote: Can we please leave the Perl Golf in the appropriate context or at least make a warning in/at the start of the message that the post may confuse beginners? I didn't make any warning in my last post. I wrote an explaination instead. I hope

Re: CODING STYLE (was Re: Count the number of lines in a file without actually iterating through the file)

2004-02-28 Thread WC -Sx- Jones
John W. Krahn wrote: Wc -Sx- Jones wrote: Most employers (and a quiet a few IT managers) are not very Perl savvy and would like you Perl people (read POD) to be more like COBOL people (read BOOKS.) Don't you mean we Perl people or are you inferring that you are not a Perl person? I apologize -

Re: CODING STYLE (was Re: Count the number of lines in a file without actually iterating through the file)

2004-02-28 Thread R. Joseph Newton
WC -Sx- Jones wrote: R. Joseph Newton wrote: Bryan Harris wrote: perl -lpe '}{*_=*.}{' file Ooh, an obfuscated verbose way of writing: perl -lpe'}{$_=$.' file Huh? Could someone explain this? The }{ makes no sense to me... Well, as Momma used to say: Just look the other

Re: Count the number of lines in a file without actually iterating through the file

2004-02-27 Thread Bryan Harris
perl -lpe '}{*_=*.}{' file Ooh, an obfuscated verbose way of writing: perl -lpe'}{$_=$.' file Huh? Could someone explain this? The }{ makes no sense to me... - B -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/

Re: Count the number of lines in a file without actually iterating through the file

2004-02-27 Thread Wiggins d Anconia
perl -lpe '}{*_=*.}{' file Ooh, an obfuscated verbose way of writing: perl -lpe'}{$_=$.' file Huh? Could someone explain this? The }{ makes no sense to me... - B You're not the first. There was recently much discussion about this on the Fun with Perl list, see the

Re: Count the number of lines in a file without actually iterating through the file

2004-02-27 Thread James Edward Gray II
On Feb 27, 2004, at 1:13 PM, Bryan Harris wrote: perl -lpe '}{*_=*.}{' file Ooh, an obfuscated verbose way of writing: perl -lpe'}{$_=$.' file Huh? Could someone explain this? The }{ makes no sense to me... I thought the same thing, when I read it! I'm still not sure I get it, but perlrun

Re: Count the number of lines in a file without actually iterating through the file

2004-02-27 Thread R. Joseph Newton
Bryan Harris wrote: perl -lpe '}{*_=*.}{' file Ooh, an obfuscated verbose way of writing: perl -lpe'}{$_=$.' file Huh? Could someone explain this? The }{ makes no sense to me... Well, as Momma used to say: Just look the other way. Ignore it, and maybe it will go away... I would

Re: Count the number of lines in a file without actually iterating through the file

2004-02-27 Thread zsdc
R. Joseph Newton wrote: Huh? Could someone explain this? The }{ makes no sense to me... Well, as Momma used to say: Just look the other way. Ignore it, and maybe it will go away... I would not be at all surprised if the code above works, and does *something*. I just prefer to use code that

CODING STYLE (was Re: Count the number of lines in a file without actually iterating through the file)

2004-02-27 Thread WC -Sx- Jones
R. Joseph Newton wrote: Bryan Harris wrote: perl -lpe '}{*_=*.}{' file Ooh, an obfuscated verbose way of writing: perl -lpe'}{$_=$.' file Huh? Could someone explain this? The }{ makes no sense to me... Well, as Momma used to say: Just look the other way. Ignore it, and maybe it will go

Re: CODING STYLE (was Re: Count the number of lines in a file without actually iterating through the file)

2004-02-27 Thread zsdc
WC -Sx- Jones wrote: Can we please leave the Perl Golf in the appropriate context or at least make a warning in/at the start of the message that the post may confuse beginners? I didn't make any warning in my last post. I wrote an explaination instead. I hope that's acceptable... -- ZSDC --

Re: CODING STYLE (was Re: Count the number of lines in a file without actually iterating through the file)

2004-02-27 Thread WC -Sx- Jones
zsdc wrote: WC -Sx- Jones wrote: Can we please leave the Perl Golf in the appropriate context or at least make a warning in/at the start of the message that the post may confuse beginners? I didn't make any warning in my last post. I wrote an explaination instead. I hope that's

Re: CODING STYLE (was Re: Count the number of lines in a file without actually iterating through the file)

2004-02-27 Thread John W. Krahn
Wc -Sx- Jones wrote: Most employers (and a quiet a few IT managers) are not very Perl savvy and would like you Perl people (read POD) to be more like COBOL people (read BOOKS.) Don't you mean we Perl people or are you inferring that you are not a Perl person? Can we please leave the Perl

RE: Count the number of lines in a file without actually iteratin g through the file

2004-02-26 Thread Charles K. Clarkson
Jenda Krynicky [EMAIL PROTECTED] wrote: : : From: WC -Sx- Jones : : undef $/; # Slurp; : : foreach $target (@ARGV) { :@lines = (); : :open (HTML_FILE, $target) or die owie; :@lines = split(/\n/, HTML_FILE); : :print In $target - Seen: . ($#lines + 1) . lines...\n; : }

Count the number of lines in a file without actually iterating through the file

2004-02-25 Thread Jason Normandin
Hi List. Is there a way to determine the number of lines in a file without actually iterating through the file and incrementing a file? I found the following on perlmonks.org, it works great but this is command line syntax : perl -lpe '}{*_=*.}{' file How could I integrate

RE: Count the number of lines in a file without actually iterating through the file

2004-02-25 Thread David le Blanc
-Original Message- From: Jason Normandin [mailto:[EMAIL PROTECTED] Sent: Thursday, 26 February 2004 10:56 AM To: Perl Beginners Subject: Count the number of lines in a file without actually iterating through the file Hi List. Is there a way to determine the number

RE: Count the number of lines in a file without actually iteratin g through the file

2004-02-25 Thread Hanson, Rob
Is there a way to determine the number of lines in a file without actually iterating through the file and incrementing a file? No. I found the following on perlmonks.org, it works great but this is command line syntax When you deparse that command (see below), you can see that all it does

Re: Count the number of lines in a file without actually iterating through the file

2004-02-25 Thread John W. Krahn
Jason Normandin wrote: Hi List. Hello, Is there a way to determine the number of lines in a file without actually iterating through the file and incrementing a file? I found the following on perlmonks.org, it works great but this is command line syntax perl -lpe '}{*_=*.}{' file Ooh

Re: Count the number of lines in a file without actually iteratin g through the file

2004-02-25 Thread WC -Sx- Jones
[ what was all that? in-line top posting? please don't ] Hanson, Rob wrote: Is there a way to determine the number of lines in a file without actually iterating through the file and incrementing a file? # No silver bullet; but shorter - undef $/; # Slurp; foreach $target (@ARGV) { @lines

pick N random lines from a file

2003-12-10 Thread David Garamond
I'm trying to extend the Perl cookbook recipe on how to pick a random line from a file: #!/usr/bin/perl rand($.) 1 ($line = $_) while ; print $line; for picking up to N random lines from a file: start code-- #!/usr/bin/perl die Usage: $0 N, where N is the number

Re: pick N random lines from a file

2003-12-10 Thread Kevin Old
On Wed, 2003-12-10 at 11:12, David Garamond wrote: I'm trying to extend the Perl cookbook recipe on how to pick a random line from a file: #!/usr/bin/perl rand($.) 1 ($line = $_) while ; print $line; for picking up to N random lines from a file: start code

Re: pick N random lines from a file

2003-12-10 Thread Robert Brown
Kevin Old writes: On Wed, 2003-12-10 at 11:12, David Garamond wrote: I'm trying to extend the Perl cookbook recipe on how to pick a random line from a file: #!/usr/bin/perl rand($.) 1 ($line = $_) while ; print $line; for picking up to N random lines from

Re: How to get 1st line, last line and no of lines in a file

2003-02-20 Thread Lance
[mailto:[EMAIL PROTECTED]] Sent: Wednesday, February 19, 2003 1:25 PM To: [EMAIL PROTECTED] Subject: How to get 1st line, last line and no of lines in a file Hi, How to get first line, last line and no of lines in a file. is there any perl functions available for that ? r

Re: How to get 1st line, last line and no of lines in a file

2003-02-20 Thread Gary Stainburn
w to get 1st line, last line and no of lines in a file Hi, How to get first line, last line and no of lines in a file. is there any perl functions available for that ? right now what i am doing is open file while (FH { $lines++; }

Re: How to get 1st line, last line and no of lines in a file

2003-02-20 Thread Lance
[EMAIL PROTECTED]... -Original Message- From: Madhu Reddy [mailto:[EMAIL PROTECTED]] Sent: Wednesday, February 19, 2003 1:25 PM To: [EMAIL PROTECTED] Subject: How to get 1st line, last line and no of lines in a file Hi, How to get first line, last line and no of lin

Re: How to get 1st line, last line and no of lines in a file

2003-02-19 Thread R. Joseph Newton
Madhu Reddy wrote: Hi, How to get first line, last line and no of lines in a file. is there any perl functions available for that ? right now what i am doing is open file while (FH { $lines++; } close(FH) This operation is expensive.. suppose, if file have millions

RE: How to get 1st line, last line and no of lines in a file

2003-02-19 Thread Paul
Subject: How to get 1st line, last line and no of lines in a file is there any perl functions available for that ? suppose, if file have millions of records, ok If it's a small file, try Tie::File by (I believe) Mark Jason Dominus. It's very cool. For a big file, I'm not sure there's

How to get 1st line, last line and no of lines in a file

2003-02-18 Thread Madhu Reddy
Hi, How to get first line, last line and no of lines in a file. is there any perl functions available for that ? right now what i am doing is open file while (FH { $lines++; } close(FH) This operation is expensive.. suppose, if file have millions of records, it will take more time

RE: How to get 1st line, last line and no of lines in a file

2003-02-18 Thread Toby Stuart
-Original Message- From: Madhu Reddy [mailto:[EMAIL PROTECTED]] Sent: Wednesday, February 19, 2003 1:25 PM To: [EMAIL PROTECTED] Subject: How to get 1st line, last line and no of lines in a file Hi, How to get first line, last line and no of lines in a file

Re: modify the first few lines of a file

2003-02-07 Thread Rob Dixon
Sashidhar wrote: I may have to change the length of the files. Is there no way, like manipulating the inode entries to reflect any changes in the length. Ofcourse, I realize that this is specific to the linux/unix env. The problem is a limitation of the filing system itself. The starting

modify the first few lines of a file

2003-02-06 Thread sashidhar
Hello, I am dealing with text files of sizes 2 GB. I have to modify just the top 2 lines of such files. Is there a way in Perl to modify just the first 'n' lines of the file without having to process rest of the file as it involves a lot of IO and time. Thanks, Siva

Re: modify the first few lines of a file

2003-02-06 Thread John W. Krahn
Sashidhar wrote: Hello, Hello, I am dealing with text files of sizes 2 GB. I have to modify just the top 2 lines of such files. Is there a way in Perl to modify just the first 'n' lines of the file without having to process rest of the file as it involves a lot of IO and time. It depends

Re: modify the first few lines of a file

2003-02-06 Thread sashidhar
dealing with text files of sizes 2 GB. I have to modify just the top 2 lines of such files. Is there a way in Perl to modify just the first 'n' lines of the file without having to process rest of the file as it involves a lot of IO and time. It depends. If the modifications don't change

Re: modify the first few lines of a file

2003-02-06 Thread John W. Krahn
Sashidhar wrote: --- John W. Krahn [EMAIL PROTECTED] wrote: Sashidhar wrote: I am dealing with text files of sizes 2 GB. I have to modify just the top 2 lines of such files. Is there a way in Perl to modify just the first 'n' lines of the file without having to process rest

Re: taking lines from a file

2003-01-30 Thread Rob Dixon
Marcelo wrote: Hi everybody... How I can take lines from a file like this ... line1=A line2 line3 line1=B line2 line3 line1=A line2 line3 I want to take the followin 2 lines to the line1 when line1=A and write them to another file I'm not clear exactly what your file looks

Re: taking lines from a file

2003-01-30 Thread John Baker
On Thu, 30 Jan 2003, Rob Dixon wrote: Date: Thu, 30 Jan 2003 16:40:13 - From: Rob Dixon [EMAIL PROTECTED] To: [EMAIL PROTECTED] Subject: Re: taking lines from a file Marcelo wrote: Hi everybody... How I can take lines from a file like this ... line1=A line2 line3 line1

Re: taking lines from a file

2003-01-30 Thread John W. Krahn
Rob Dixon wrote: Marcelo wrote: Hi everybody... How I can take lines from a file like this ... line1=A line2 line3 line1=B line2 line3 line1=A line2 line3 I want to take the followin 2 lines to the line1 when line1=A and write them to another file I'm

RE: NewbieQuestion Deleting the first 5 lines of a file

2003-01-24 Thread Bob Showalter
[EMAIL PROTECTED] wrote: Hello, I have over 1000 files that I need to delete the first five lines of text from. This needed to be done, like yesterday. I started writting an Applescript to do this but ran into a bug with Folder Actions and attached scripts that stopped my progress dead.

RE: NewbieQuestion Deleting the first 5 lines of a file

2003-01-24 Thread jeff . thomas
All files will be in the same directory. The files are Postscript. They all have a proprietary header with comments above the %!PS line so they all fail to print. At 24/01/2003 14:48:47, Kipp, James [EMAIL PROTECTED] wrote: Hello, I have over 1000 files that I need to delete the first five

RE: NewbieQuestion Deleting the first 5 lines of a file

2003-01-24 Thread Bob Showalter
[EMAIL PROTECTED] wrote: Subject: RE: NewbieQuestion Deleting the first 5 lines of a file At 24/01/2003 15:29:27, Bob Showalter [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] wrote: Hello, I have over 1000 files that I need to delete the first five lines of text from. This needed

RE: NewbieQuestion Deleting the first 5 lines of a file

2003-01-24 Thread jeff . thomas
At 24/01/2003 15:29:27, Bob Showalter [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] wrote: Hello, I have over 1000 files that I need to delete the first five lines of text from. This needed to be done, like yesterday. I started writting an Applescript to do this but ran into a bug with

RE: NewbieQuestion Deleting the first 5 lines of a file

2003-01-24 Thread Kipp, James
perl -i.bak -ne 'print if $.5; close ARGV if eof' *.txt Bob I have been trying to figure out a different solution then using the -i arg. Is there a simple way to just open each file, delete the 5 lines in place and close it(with no backup file), without getting into sysread, truncate

RE: NewbieQuestion Deleting the first 5 lines of a file

2003-01-24 Thread Bob Showalter
Kipp, James wrote: perl -i.bak -ne 'print if $.5; close ARGV if eof' *.txt Bob I have been trying to figure out a different solution then using the -i arg. Is there a simple way to just open each file, delete the 5 lines in place and close it(with no backup file), without getting

RE: NewbieQuestion Deleting the first 5 lines of a file

2003-01-24 Thread Kipp, James
have been trying to figure out a different solution then using the -i arg. Is there a simple way to just open each file, delete the 5 lines in place and close it(with no backup file), without getting into sysread, truncate, etc... Not really. What's the problem with using -i? nothing

Re: NewbieQuestion Deleting the first 5 lines of a file

2003-01-24 Thread Rob Dixon
James Kipp wrote: have been trying to figure out a different solution then using the -i arg. Is there a simple way to just open each file, delete the 5 lines in place and close it(with no backup file), without getting into sysread, truncate, etc... Not really. What's the problem with using

RE: NewbieQuestion Deleting the first 5 lines of a file

2003-01-24 Thread Kipp, James
[snip] but we still have not changed the original file, have we :-) There isn't a way to edit a text file anywhere except the end without copying the data. Deleting from the beginning requires that all data after the deletion are moved up to the start of the file. You could do it within

Question about seek, Was: Trailing 5 lines of a file

2002-10-31 Thread Kipp, James
Where can i find more info on seek(), perldoc does not tell me much. it only list 3 parameters, where David uses 4 in this code? what do negative values in the offset represent? Thanks #!/usr/bin/perl -w use strict; my @character; my @lines; open(FH,foo.txt) || die $!; seek(FH,(-s

Re: Question about seek, Was: Trailing 5 lines of a file

2002-10-31 Thread Frank Wiles
.--[ Kipp, James wrote (2002/10/31 at 09:28:23) ]-- | | Where can i find more info on seek(), perldoc does not tell me much. it only | list 3 parameters, where David uses 4 in this code? what do negative values | in the offset represent? | | seek(FH,tell(FH)-2,0); |

RE: Question about seek, Was: Trailing 5 lines of a file

2002-10-31 Thread Kipp, James
;wiles.org] Sent: Thursday, October 31, 2002 9:38 AM To: Kipp, James Cc: [EMAIL PROTECTED] Subject: Re: Question about seek, Was: Trailing 5 lines of a file Actually there are only three. FH, tell(FH)-2, and 0. If you use 2 for the WHENCE value you can use negative values

Re: Question about seek, Was: Trailing 5 lines of a file

2002-10-31 Thread Frank Wiles
.--[ Kipp, James wrote (2002/10/31 at 09:53:10) ]-- | | Thanks. I looked throught Programming perl but did not find much. Ok, I see | i misread the statement and ther are only 3 params. Here is how I read this | statment: | seek(FH,(-s foo.txt)-2,0); | | seek back 2 bytes

  1   2   >