VectorLinux

Please login or register.

Login with username, password and session length
Advanced search  

News:

Visit our home page for VL info. For support and documentation, visit the Vector Linux Knowledge Center or search the Knowledge Center and this Forum using the search box above.

Author Topic: Finding out how many lines there (really) are in a file.  (Read 5306 times)

Daniel

  • Packager
  • Vectorian
  • ****
  • Posts: 704
    • TuxToys - Packages for VectorLinux 6.0
Finding out how many lines there (really) are in a file.
« on: October 27, 2009, 11: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
Re: Finding out how many lines there (really) are in a file.
« Reply #1 on: October 27, 2009, 02: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
    • TuxToys - Packages for VectorLinux 6.0
Re: Finding out how many lines there (really) are in a file.
« Reply #2 on: October 27, 2009, 02: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, 02: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
Re: Finding out how many lines there (really) are in a file.
« Reply #3 on: October 27, 2009, 02: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
Re: Finding out how many lines there (really) are in a file.
« Reply #4 on: October 28, 2009, 01:52:47 am »

isn't that just counting EOL characters in a file?
Logged
desktop: no more (gave to sister :D)
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
    • Joe1962's Website
Re: Finding out how many lines there (really) are in a file.
« Reply #5 on: October 28, 2009, 07: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... ;D
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