count lines 
Author Message
 count lines

Hi there,

Is there a possibility to count the lines in a file with ruby?

Any anwer would be very helpful.

Thanks

Gustav



Fri, 05 Aug 2005 09:40:41 GMT  
 count lines

Quote:

> Hi there,
> Is there a possibility to count the lines in a file with ruby?

count.rb

  lines = 0
  ARGF.each do |line|
    lines += 1
  end

Run it as:

  ruby count.rb file ...

Gavin



Fri, 05 Aug 2005 09:51:50 GMT  
 count lines

Quote:


>> Hi there,
>> Is there a possibility to count the lines in a file with ruby?
> count.rb
>   lines = 0
>   ARGF.each do |line|
>     lines += 1
>   end

    puts lines
Quote:
> Run it as:
>   ruby count.rb file ...
> Gavin



Fri, 05 Aug 2005 10:05:38 GMT  
 count lines
How about this.

  open("filename"){|f| p f.readlines.size}

Shin

Quote:
>Hi there,

>Is there a possibility to count the lines in a file with ruby?

>Any anwer would be very helpful.

>Thanks

>Gustav



Fri, 05 Aug 2005 10:08:40 GMT  
 count lines
Quote:

> How about this.

>   open("filename"){|f| p f.readlines.size}

> Shin

> >Hi there,

> >Is there a possibility to count the lines in a file with ruby?

> >Any anwer would be very helpful.

> >Thanks

> >Gustav

Very nice.

Thanks a lot.



Fri, 05 Aug 2005 16:32:14 GMT  
 count lines

Quote:


> > How about this.

> >   open("filename"){|f| p f.readlines.size}

> > Shin

        [...]
> Very nice.

> Thanks a lot.

Not forgetting:
ruby -ne 'END {puts $.}' file
from
http://www.rubygarden.org/ruby?OneLiners

        Hugh



Fri, 05 Aug 2005 22:08:16 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Match then count lines

2. Counting lines in a report

3. counting lines in a report

4. how can i count line wich begins with NCOUNT word

5. Count lines in text file

6. Program that counts lines per minute

7. A tool to count lines in Ada programs

8. No More Counting Lines of COBOL Code

9. how to count lines in a file ?

10. how to count lines in a file ?

11. Counting lines of code in Prolog (source code)

12. counting lines

 

 
Powered by phpBB® Forum Software