LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

I need to retrieve only the first and the last line of a text File

I would be very happy if some one of you can help me.
I attached a text File as example
thanks

Jules
0 Kudos
Message 1 of 4
(2,849 Views)
use the read from spreadsheet file.vi
find the 2D array size---number of rows (index 0)

then use the index array function
(
index 0 or the first line
index (number rows -1 for the last line)
Message 2 of 4
(2,842 Views)
thank you very much.This was what i need.

Jules
0 Kudos
Message 3 of 4
(2,827 Views)
Hi,

In the file I/O functions there is an Advanced File Functions sub menu.
There you can open a reference to a file, and read data from it. The first
line is easy, just use Read File, and set the Line Mode (F) to true.

The last line is a bit trickier. You can use the Seek function to get the
length of the file. Set a counter to this position-1. Read one character
from this position. Subtract the position with one, and read another
charater. Put is before the previous string. Repeat until a \n is
encountered.

If you know how long the last line is going to be at maximum, you can read
this number of characters, and split the string on the last \n. This is
easier but not general appliable.

Also think about what you want to do when the last line is the first line.

Note that this method is only worth the effort when the files get large
(below a few MB I'd use a method like suggested by Dr. Imad).

Regards,

Wiebe.



"Jules K." <x@no.email> wrote in message news:169785@exchange.ni.com...
> I would be very happy if some one of you can help me.<br>I attached a text
File as example<br>thanks<br><br>Jules
>
>
> text_file.txt:
> http://forums.ni.com/attachments/ni/170/100033/1/text_file.txt


0 Kudos
Message 4 of 4
(2,818 Views)