02-02-2022 09:53 AM - edited 02-02-2022 09:55 AM
Hi All,
I have a text file which is formatted as follows:
[Part Number]
123123
[Batch Number]
456456
[Work Order Number]
789789
and so on... Always with a [parameter] followed by some data.
How would I search the file and return just the data for a single parameter ? For example, If i wanted to search the file and return just the Batch Number (456456), is this possible ? I can't seem to get any of the built in string functions to work for me?
Thanks in advance for your help,
02-02-2022 10:35 AM - edited 02-02-2022 11:06 AM
Well, first you would read the entire file, then operate on the resulting string. Then you would use a while loop to search for the parameter(+linefeed) and then read read the following line until all are found.
It is hard to tell what you are doing wrong unless you show us what you are doing. Note that you probably need to escape some characters (e.g. [,], etc.) that have special meaning in expressions.
02-02-2022 10:56 AM
You can also read the file as an array of lines, simplifying the rest of the code a little bit. Here are two possible approaches:
(note that you can directly read the file as an array of lines using read from text file)
02-02-2022 11:04 AM - edited 02-02-2022 11:07 AM
Here's how you could use match pattern (note the "\" to change the meaning)
Might need a few tweaks, depending how EOL is defined (LF, CRLF, etc.). There are dozens of different ways to do all that, of course. Try to find a few more! 😄