VectorLinux

Cooking up the Treats => Help Wanted-Developers => Topic started by: Daniel on October 27, 2009, 11:25:41 am

Title: Finding out how many lines there (really) are in a file.
Post by: Daniel 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?
Title: Re: Finding out how many lines there (really) are in a file.
Post by: sparkyhall 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?
Title: Re: Finding out how many lines there (really) are in a file.
Post by: Daniel 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.
Title: Re: Finding out how many lines there (really) are in a file.
Post by: newt 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!
Title: Re: Finding out how many lines there (really) are in a file.
Post by: barret on October 28, 2009, 01:52:47 am
isn't that just counting EOL characters in a file?
Title: Re: Finding out how many lines there (really) are in a file.
Post by: Joe1962 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