LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Does anyone know why LV does not have any native function that will return the number of lines in a file?

Something like like,

"wc -l" in UNIX.

Any ideas why and what is the most efficient work -around?

Ben
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 1 of 9
(3,710 Views)
Ben,

Its probably not in LabVIEW because it is a native UNIX call, and is not found on the Mac or Windows.

I suggest creating a VI that searches for carriage returns or newlines, and counts them. It should be pretty easy, but I don't know how efficient it will be.

I don't believe that there are any equivalent system calls in Windows or Macs. I think that with Windows, there probably isnt any way to know the number of lines in a file, besides counting them.

Good luck, and let us know how you do.

-Mike
Message 2 of 9
(3,710 Views)
I don't know why there isn't a function like that (unless I just missed it). What type of file are you dealing with? If it's a numeric data file then you could read the data out with "Read From Spreadsheet File.vi". You could then take the array from that .vi and wire to the Array Size function to report the number of rows and columns. If you are using a different type of file, then there are other ways to figure out the number of lines.

Regards
SW
Message 3 of 9
(3,710 Views)
A quick look at a UNIX man page for the wc command says it simply prints the newline count.

Attached is a silly little vi (in 6.0.2) that counts any character (or matched patterns) you'd like. Doubtless you could have done it yourself, but I needed one anyway 🙂
Message 4 of 9
(3,710 Views)
Hi Ben,
here's a little sub.vi that approaches it from a different tack - instead of searching by character, you use the read lines sub.vi to do the same job, which also allows you to set a maximum line length too.

Hope it helps

S.
// it takes almost no time to rate an answer Smiley Wink
Message 5 of 9
(3,710 Views)
Labviewguru,
Swatson,
Underflow,
SachaE,

I want to thank you very much for your replies!

Here is the reason I asked.

I was consulting on-site yesterday for a rather proficient customer who posed the above question to me.

After reminding myself that the file VI return a byte count and not a line count, I said, Let's ask the experts, here, I will show you how.

So I posted this question and said we should have some sort of answer by tomorow.

You all are great!

In your replies, you have not only addressed the "why" part of my query but you have also given me three different solutions!

"There is wisdom in a multitude of counselors" (Proverbs)

Thank you all again!

I will make an attempt to re-pay this service in the future.

Ben
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 6 of 9
(3,710 Views)
> I suggest creating a VI that searches for carriage returns or
> newlines, and counts them. It should be pretty easy, but I don't know
> how efficient it will be.
>

If all you're doing is looking for line terminators, the code should
be pretty efficient because you aren't actually moving the string
itself around--just a pointer into it.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 7 of 9
(3,710 Views)
Hi,

Just be carefull, some text editors use /r/n for a new line, some use /r,
some use /n.

If you check all /r or /n, you might get twice as much lines. So, check for
/r/n, /r and /n!

Regards,

Wiebe.

"Labviewguru" wrote in message
news:50650000000500000048A10000-1031838699000@exchange.ni.com...
> Ben,
>
> Its probably not in LabVIEW because it is a native UNIX call, and is
> not found on the Mac or Windows.
>
> I suggest creating a VI that searches for carriage returns or
> newlines, and counts them. It should be pretty easy, but I don't know
> how efficient it will be.
>
> I don't believe that there are any equivalent system calls in Windows
> or Macs. I think that with Windows, there probably isnt any way to
> know the number
of lines in a file, besides counting them.
>
> Good luck, and let us know how you do.
>
> -Mike
0 Kudos
Message 8 of 9
(3,710 Views)
Phew,
no body noticed the "deliberate" mistake in my .vi. I was taking off the index to the while loop as the number of lines in the file, and completely forgot to add one to it!
New version below.

Sorry to all those who've picked it up and discovered there's one more line than the .vi says there is.

S.
// it takes almost no time to rate an answer Smiley Wink
0 Kudos
Message 9 of 9
(3,710 Views)