From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

"Grepping" from text file example.vi?

Anyone have an example vi to "grep" from a text file for relevant strings, then write the reformatted strings to another file?

Basically looking to create a vi to function like wingrep. . .

0 Kudos
Message 1 of 11
(3,444 Views)

Hi msp,

 

basically you use File functions to read your textfile into a string. Then you use String functions (like MatchPattern) to search for your strings of interest. You collect your data in an appropriate data structure (like an array or a cluster) and you will use other file functions to create your "another file"…

 

What have you tried so far? Where are you stuck?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 11
(3,434 Views)

Hey, thanks for your time!

Yes, I guess you could say I'm stuck! I've tried match pattern, match regular expression, scan from file etc. . .

I would have an example but I was disgusted and deleted them to start over. Reading and writing from text files seems to be pretty straight-forward, I seem to be stuck on pulling out the lines of text that I want, and reformatting it to a new file.

Some of the log files will be hundreds of lines. . .I seem to be hung up on reading all the lines, my vi's seem to stop at the first line.

;-(

0 Kudos
Message 3 of 11
(3,419 Views)

Hi msp,

 

you should provide example "log files" and explain, which "lines of text" you are interested in! Give an example of "reformatting it" too…

 

 

As long as you ask GENERIC questions you will only get GENERIC answers!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 11
(3,407 Views)

Greetings,

 

Here's a short  example of my logged data:

 

I would like to format the log data to show something like this:

 

 20150121 202454 Print Pass # 346 Facets: 20875 Start facet: 10

 

20150121 202450 54c07b92 DEB I PSU:0x20a0000 10b7006d 0 printControl.cpp 3820 VG ready timeout detected this pass
20150121 202454 54c07b96 DEB I prt:0x20a0000 Print Pass # 346
. Stripe: 173550720.0000 (nm) 21539235.4440 (LMS) Scan: 233503952.0000 (nm) 30119199.0020 (LMS)
. Facets: 20875 Start facet: 10
.
20150121 202500 54c07b9c DEB I PSU:0x20a0000 10b7006d 0 printControl.cpp 3820 VG ready timeout detected this pass
20150121 202505 54c07ba1 DEB I prt:0x20a0000 Print Pass # 347
. Stripe: 142094760.0000 (nm) 46989538.1471 (LMS) Scan: 233766032.0000 (nm) 30333530.7008 (LMS)
. Facets: 44971 Start facet: 18
.
20150121 202515 54c07baa DEB I PSU:0x20a0000 10b7006d 0 printControl.cpp 3820 VG ready timeout detected this pass
20150121 202516 54c07bac DEB I prt:0x20a0000 Print Pass # 348
. Stripe: 142093440.0000 (nm) 46990591.7200 (LMS) Scan: 234028240.0000 (nm) 30545677.4944 (LMS)
. Facets: 45035 Start facet: 10
.
20150121 202526 54c07bb5 DEB I PSU:0x20a0000 10b7006d 0 printControl.cpp 3820 VG ready timeout detected this pass
20150121 202527 54c07bb7 DEB I prt:0x20a0000 Print Pass # 349
. Stripe: 142094760.0000 (nm) 46989509.3554 (LMS) Scan: 234290320.0000 (nm) 30757720.5475 (LMS)
. Facets: 45035 Start facet: 18
.

NOTE: I seemed by having some issues with the match regular expressions function. It didn't like the null characters. . .

0 Kudos
Message 5 of 11
(3,400 Views)

Hi msp,

 

an example:

check.png

Just to show the basics of string handling…

(There might be other ways too, including RegEx parsing.)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 6 of 11
(3,388 Views)

Hey, thanks!! Great example. Especially if I can get it to work for me.

LabVIEW:  Scan failed. The input string does not contain data in the expected format.

Looks like its hanging up at the Scan From String Function. I clearly messed something up. . .

I'll keep staring at it for a while. . .

 

 

 

 

 

 

 

0 Kudos
Message 7 of 11
(3,349 Views)

Greetings again,

 

Still struggling! ;-( Maybe I wired up the false condition wrong in the case structure? I'll attach the vi for your reference.

Thanks for all the help. . . much appreciated!

 

MSP

0 Kudos
Message 8 of 11
(3,315 Views)

Yes, in the false case, you wired "c" to the shift register that's collecting your "Filtered rolling". C is going to be empty in the last itteration because the match pattern won't be found. This clears out your "filtered rolling" shift register. You can see this if you turn on highlight execution and probe around.  You should wire the incomming shift register back out in the false case because you don't want to make any changes to the "filtered rolling" buffer. Also, you appear to be missing a space after the period in

. Facets: %d Start facet: %d

Lastly, you probably want to print a new line at the end of

 

Print Pass # %d Facets:  %d Start facet: %d
Message 9 of 11
(3,311 Views)

Hi msp,

 

the next time you want to make comments on the name of functions you use in your VI: simply right-click them and show their label…

 

But better get rid of such comments and show the context help window. It also shows the name of each function in your VI!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 10 of 11
(3,279 Views)