VectorLinux
July 23, 2014, 05:57:03 pm *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Visit our home page for VL info. To search the old message board go to http://vectorlinux.com/forum1. The first VL forum is temporarily offline until we can find a host for it. Thanks for your patience.
 
Now powered by KnowledgeDex.
   Home   Help Search Login Register  
Please support VectorLinux!
Pages: [1]
  Print  
Author Topic: Finding out how many lines there (really) are in a file.  (Read 4662 times)
Daniel
Packager
Vectorian
****
Posts: 704


WWW
« on: October 27, 2009, 10:25:41 am »

I'm working on a script in which I need to find out how many lines there are in a file. Someone previously suggested using wc -l to find this out. That worked until I tried it on a .png file, a .jpg file, and a .mpg video file. When I tried it on the .png and .jpg files, it missed the last line. When I tried it on the .mpg file, (which had about 55,000 lines) it found only about 24,000 lines. I can open these files in a text editor and find out how many lines there are but I need to be able to find out by using commands that return the number of lines to the program. Any ideas?
Logged

The following sentence is true. The previous sentence is false.

VL 6.0 SOHO KDE-Classic on 2.3 Ghz Dual-core AMD with 3 Gigs of RAM
sparkyhall
Vectorite
***
Posts: 118


« Reply #1 on: October 27, 2009, 01:00:15 pm »

I don't understand the question.

The file extensions you have refered to are either image or movie file types so they do not contain lines. It's a bit like asking someone to count the number of lines on a photograph. Are you simply trying to find out the size of the files?
Logged
Daniel
Packager
Vectorian
****
Posts: 704


WWW
« Reply #2 on: October 27, 2009, 01:22:56 pm »

The file extensions you have refered to are either image or movie file types so they do not contain lines.

If you open an image or movie file in a text editor you can see the lines. You can also do: cat image.png to see the lines in an image file. To clarify, I am trying to use a command to count those lines and report that number back to the script. I am not trying to determine the size of the file.
« Last Edit: October 27, 2009, 01:24:57 pm by Daniel » Logged

The following sentence is true. The previous sentence is false.

VL 6.0 SOHO KDE-Classic on 2.3 Ghz Dual-core AMD with 3 Gigs of RAM
newt
Vectorian
****
Posts: 1132



« Reply #3 on: October 27, 2009, 01:59:34 pm »

Here's a thread dealing with lines in a file. I wonder if you'd find something useful in here:
http://www.unix.com/shell-programming-scripting/43657-total-number-lines-file.html

Good luck!
Logged
barret
Member
*
Posts: 75


« Reply #4 on: October 28, 2009, 12:52:47 am »

isn't that just counting EOL characters in a file?
Logged

desktop: no more (gave to sister Cheesy)
laptop: DELL D600 / 1.5 ghz / 1 GB / 8 GB CF / Radeon 9000 / VL6 / Win XP
Registered Linux User #417845
“Strange women lying in ponds distributing swords is no basis for a system of government!”
Joe1962
Administrator
Vectorian
*****
Posts: 2499



WWW
« Reply #5 on: October 28, 2009, 06:40:09 am »

Like sparkyhall said, those are binary files, so they don' t have defined lines. What look like lines to a text editor is simply when the binary values coincide with the end of line character or characters. These files have a defined structure that is documented in some cases, not in others. Reading the number of lines in one of these files makes no sense, at least that I can figure out... Grin
Logged

O'Neill (RE the Asgard): "Usually they ask nicely before they ignore us and do what they damn well please."
http://joe1962.bigbox.info
Running: VL 7 Std 64 + self-cooked XFCE-4.10
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!