LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Find and edit specific line in text file?

Hello I want to read a text file that could look in some different ways since the user choose file from a list. I then want to igonre all the lines that begin with a special character, for example %. I then want to find all the lines "words" that begin with TRY for example and put those "words" in a string or array. If there is one line that contains TRY100 and anoter line that contains TRY200 I want to find those words and display them. How do i do this?

0 Kudos
Message 1 of 12
(6,220 Views)

@qweewq11 wrote:

Hello I want to read a text file that could look in some different ways since the user choose file from a list. I then want to igonre all the lines that begin with a special character, for example %. I then want to find all the lines "words" that begin with TRY for example and put those "words" in a string or array. If there is one line that contains TRY100 and anoter line that contains TRY200 I want to find those words and display them. How do i do this?


Instead of expecting someone to provide you with a VI, you need to demonstrate that you have attempted to do this.

 

Post your VI.

0 Kudos
Message 2 of 12
(6,218 Views)

But who said i want someone to provide me with a VI? I don't even want a VI since I can't open it on my computer, I want someone to give me tips and tell me if there is a good way to do this and then I can do it my self. I can't really find any functions that can do what I want and I can't find any good solution to my problem.

0 Kudos
Message 3 of 12
(6,211 Views)

First you read the entire file.  Use the Read Text File.  Right-click on it and select the option to Read Lines.  The the count to read to -1 (read all).  You will now have an array of strings, one item for each line of your file.

 

Now you need to play the filter game.  I recommend using FOR loops with Autoindexing tunnels.  Assuming you are using 2012 or later, have the output autoindexing tunnels use the conditional tunnel.

 

Give this a try and see where you can go.  Post back with what you have tried and tell us where you are stuck.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 12
(6,209 Views)

@qweewq11 wrote:

But who said i want someone to provide me with a VI? I don't even want a VI since I can't open it on my computer, I want someone to give me tips and tell me if there is a good way to do this and then I can do it my self. I can't really find any functions that can do what I want and I can't find any good solution to my problem.


HOLD it your are posting on the NI discussion forums LabVIEW board and you "cannot open a vi?"

 

However, you can learn more here by mistake than most places.

 

Have you ever heard of a Regex or, "Regular expression?"  Just click the blue text... It will take you someplace nice..


"Should be" isn't "Is" -Jay
0 Kudos
Message 5 of 12
(6,203 Views)

@qweewq11 wrote:

But who said i want someone to provide me with a VI? I don't even want a VI since I can't open it on my computer, I want someone to give me tips and tell me if there is a good way to do this and then I can do it my self. I can't really find any functions that can do what I want and I can't find any good solution to my problem.


You can't find any good solution?

 

How about looking at the Examples that ship with LabVIEW?

Or reading a tutorial or two?

 

 

0 Kudos
Message 6 of 12
(6,195 Views)

Hi qweewq11,

 

Saying that you don't want a VI is quite confusing here. Are you looking for a LabVIEW solution or a non-LabVIEW solution ?

 

If you want to go with LabVIEW, just follow the recommandations of crossrulz and you should go in the right direction.

 

If you are looking for a non-LabVIEW solution, there are languages more suited for text processing, like Perl. But then you are not on the right forum 😉

 

In any case, the keyword here will be the regular expression, just as Jeff suggested above ! For LabVIEW, be sure to check the "Match Regular Expression" function. 

 

Kind regards,

Cédric | NI Belgium
0 Kudos
Message 7 of 12
(6,160 Views)

Thanks I solved it buy using Match Pattern i a for loop and then put all my words in an array. In the array i removed all the blank elemets that are in between. My problem now is if a line starts with for example % i want to remove that line. So if i have an 1d array with the lines %abc, bcd, %cde and def i want to remove the lines with %abc and %cde and keep bcd and def. Any idea of how i coluld make that possible. I have tried to find a solution for hours.

0 Kudos
Message 8 of 12
(6,148 Views)

What version of LabVIEW are you using?  If using 2012 or newer, you can use Conditional tunnels on a FOR loop.  So you autoindex your array of strings into the FOR loop.  Use String Subset to just look at the first character and check that it is not a "%".  So you will autodindex out of your FOR loop the original string, except that you have the conditional on it.  Use the output of the Not Equal as your condition.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 9 of 12
(6,143 Views)

No i use older versions than 2012 unfortunately... 

0 Kudos
Message 10 of 12
(6,139 Views)