LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I open a file and read a specific line within the file?

I need to search for a certain string within the file and then read the next line in the same file. Does anybody know how to do that?
0 Kudos
Message 1 of 10
(3,469 Views)
Hi,

Open your file and than use the "Read File" function with "line mode (F)" set to True. This will read your file line by line. Use the "Match pattern" function to search for your string. Do this in a while loop. the while loop ends when a) the end of file is reached or b) the string has been found. If the string has been found read in the next line and you have it.

Waldemar
Waldemar

Using 7.1.1, 8.5.1, 8.6.1, 2009 on XP and RT
Don't forget to give Kudos to good answers and/or questions
0 Kudos
Message 2 of 10
(3,469 Views)
"ejosh" wrote:
> I need to search for a certain string within the file and then read
> the next line in the same file. Does anybody know how to do that?

Use the Read File function with "line mode" set to True in a while loop.
After each read, use Match Pattern to see if your string was in that line just
read. When you find it, exit the while loop and do one more Read File in line
mode. That should be your desired line. Read the help info for Read File for
more details you need. Of course, you have to Open and Close the file at the
appropriate points. And be sure to make the while loop exit if Read File
returns an error. Good luck! Happy wiring!

Joe Czapski
AutoMeasure
Boston, Mass.
0 Kudos
Message 3 of 10
(3,469 Views)
"ejosh" wrote:
> I need to search for a certain string within the file and then read
> the next line in the same file. Does anybody know how to do that?

Use the Read File function with "line mode" set to True in a while loop.
After each read, use Match Pattern to see if your string was in that line just
read. When you find it, exit the while loop and do one more Read File in line
mode. That should be your desired line. Read the help info for Read File for
more details you need. Of course, you have to Open and Close the file at the
appropriate points. And be sure to make the while loop exit if Read File
returns an error. Good luck! Happy wiring!

Joe Czapski
AutoMeasure
Boston, Mass.
0 Kudos
Message 4 of 10
(3,469 Views)
"ejosh" wrote:
> I need to search for a certain string within the file and then read
> the next line in the same file. Does anybody know how to do that?

Use the Read File function with "line mode" set to True in a while loop.
After each read, use Match Pattern to see if your string was in that line just
read. When you find it, exit the while loop and do one more Read File in line
mode. That should be your desired line. Read the help info for Read File for
more details you need. Of course, you have to Open and Close the file at the
appropriate points. And be sure to make the while loop exit if Read File
returns an error. Good luck! Happy wiring!

Joe Czapski
AutoMeasure
Boston, Mass.
0 Kudos
Message 5 of 10
(3,469 Views)
"ejosh" wrote:
> I need to search for a certain string within the file and then read
> the next line in the same file. Does anybody know how to do that?

Use the Read File function with "line mode" set to True in a while loop.
After each read, use Match Pattern to see if your string was in that line just
read. When you find it, exit the while loop and do one more Read File in line
mode. That should be your desired line. Read the help info for Read File for
more details you need. Of course, you have to Open and Close the file at the
appropriate points. And be sure to make the while loop exit if Read File
returns an error. Good luck! Happy wiring!

Joe Czapski
AutoMeasure
Boston, Mass.
0 Kudos
Message 6 of 10
(3,469 Views)
"ejosh" wrote:
> I need to search for a certain string within the file and then read
> the next line in the same file. Does anybody know how to do that?

Use the Read File function with "line mode" set to True in a while loop.
After each read, use Match Pattern to see if your string was in that line just
read. When you find it, exit the while loop and do one more Read File in line
mode. That should be your desired line. Read the help info for Read File for
more details you need. Of course, you have to Open and Close the file at the
appropriate points. And be sure to make the while loop exit if Read File
returns an error. Good luck! Happy wiring!

Joe Czapski
AutoMeasure
Boston, Mass.
0 Kudos
Message 7 of 10
(3,469 Views)
"ejosh" wrote:
> I need to search for a certain string within the file and then read
> the next line in the same file. Does anybody know how to do that?

Use the Read File function with "line mode" set to True in a while loop.
After each read, use Match Pattern to see if your string was in that line just
read. When you find it, exit the while loop and do one more Read File in line
mode. That should be your desired line. Read the help info for Read File for
more details you need. Of course, you have to Open and Close the file at the
appropriate points. And be sure to make the while loop exit if Read File
returns an error. Good luck! Happy wiring!

Joe Czapski
AutoMeasure
Boston, Mass.
0 Kudos
Message 8 of 10
(3,469 Views)
"ejosh" wrote:
> I need to search for a certain string within the file and then read
> the next line in the same file. Does anybody know how to do that?

Use the Read File function with "line mode" set to True in a while loop.
After each read, use Match Pattern to see if your string was in that line just
read. When you find it, exit the while loop and do one more Read File in line
mode. That should be your desired line. Read the help info for Read File for
more details you need. Of course, you have to Open and Close the file at the
appropriate points. And be sure to make the while loop exit if Read File
returns an error. Good luck! Happy wiring!

Joe Czapski
AutoMeasure
Boston, Mass.
0 Kudos
Message 9 of 10
(3,469 Views)
i tried what was suggested but came up with some problems...is there
some place you can direct me to where i could look up an example. the
second read file has invalid inputs...well i'm stuck there.
thanks,
-U
0 Kudos
Message 10 of 10
(3,469 Views)