Extract text from file

(imported topic written by Dan_Spain)

Extracting information from a file

I have some troubles about parsing text from a local file.

There are some log files in a folder. The content of one is like this:


  • Start Install Bartech Bartech 3.6.0

Instalación Bartech

2013/09/23 15:30

.

.

.

  • == INSTALACION OK

2013/09/23 15:35


  • Finish Install Bartech Bartech 3.6.0 -

The idea is to parse the text of all files to obtain the following string:

Line 2: Filtered == Bartech Bartech 3.6.0

Line 5: Complete == 2013/09/23 15:30

Last Line - 5: Complete == 2013/09/23 15:35

Last Line - 6: Filtered == INSTALACION OK

The results will be like that:

Bartech Bartech 3.6.0 - 2013/09/23 15:30 - 2013/09/23 15:35 | INSTALACION OK

First problem found: Failed query when obtaining the same line for some files

Q: names of files whose ((name of it ends with “.Log”)) of folder “C:\temp” as string

A: TEM-Install-BartechBartech360.Log

A: TEM-Install-CopyFile290Mb.Log

T: 0.571 ms

Q: (following text of position 18 of line 2 of file whose ((name of it ends with “.Log”)) of (folder “C:\temp”)) as string

A: Bartech Bartech 3.6.0

E: Singular expression refers to non-unique object.

Second problem found: Problem to concatenate

Q: ((following text of position 18 of line 2 of it) & " - " & (line 5 of it)) of file “C:\temp\TEM-Install-BartechBartech360.Log”

A: Bartech Bartech 3.6.0 - 2013/09/23 15:30

T: 0.447 ms

Q: ((number of lines of it as integer) - 5) of file “C:\temp\TEM-Install-BartechBartech360.Log”

A: 14

T: 0.545 ms

Q: ((following text of position 18 of line 2 of it) & " - " & (line 5 of it) & ((number of lines of it as integer) - 5)) of file “C:\temp\TEM-Install-BartechBartech360.Log”

E: The operator “concatenate” is not defined.

So i have at this moment two errors, one for obtaing the same content from various files an one problem for concatenate various results. Anybody can assist me?

(imported comment written by NoahSalzman)

“Singular expression…” error means “You asked for 1 (singular) thing but your Relevance query found many (plural) things.” Change “following text” to “following texts” and the problem might go away. Or, you may need “files” instead of “file”. You have to ask yourself "will there ever be more than 1 of the objects text, line, or file. If there can be more than one, and you only want a singular result, then you have to use “whose” to limit the things returned.

Concatenation: you can only concatenate strings (text). So, you need to covert your integer to a string before you concatenate it. Here is an example of “as string” using a different file.

q:
((following text
of
position
1

of
line
2

of

it
)
&

" - "

&
(line
1

of

it
)
&
((
number of
lines
of

it

as
integer)

5
)
as string
)
of
file
"C:\test.txt"

(imported comment written by Dan_Spain)

Thanks NoahSalzman, but i have try to implent your query without success:

I changed the original expresión:

Q: (following text of position 18 of line 2 of files whose ((name of it ends with “.Log”)) of (folder “C:\temp”)) as string

A: Bartech Bartech 3.6.0

E: Singular expression refers to non-unique object.

To this one: (add plurals)
== ERROR

Q: (following
texts
of position 18 of line 2 of file whose ((name of it ends with “.Log”)) of (folder “C:\temp”)) as string

A: Bartech Bartech 3.6.0

E: Singular expression refers to non-unique object.

The purpouse is filter to some files, not to one file.

The second question is to concatenate this two expresions

  1. = OK

Q: ((following text of position 18 of line 2 of it) & " - " & (line 5 of it) & ((number of lines of it as integer) - 5) as string) of file “C:\temp\TEM-Install-BartechBartech360.Log”

A: Bartech Bartech 3.6.0 - 2013/09/23 15:3014

T: 0.579 ms

  1. = OK

Q: following text of position 5 of line ( (number of lines of it as integer) - 5) of file “C:\temp\TEM-Install-BartechBartech360.Log”

A: INSTALACION OK

T: 0.604 ms

      1. == ERROR

Q: ((following text of position 18 of line 2 of it) & " - " & (line 5 of it) & (following text of position 5 of line ( (number of lines of it as integer) - 5)) of file “C:\temp\TEM-Install-BartechBartech360.Log”

E: This expression could not be parsed.

Someone has implemented something similar?

(imported comment written by NoahSalzman)

q:
((following text
of
position
18

of
line
2

of

it
)
&

" - "

&
(line
5

of

it
)
&

" - "

&
(line (
number of
lines
of

it

4
)
of

it
)
&

" "

&
following text
of
position
5

of
line ((
number of
lines
of

it

as
integer)

5
)
of

it
)
of
(files
of
folder
"c:\temp"
)
whose
(name
of

it

ends with

“.Log”

and
(
exists
lines
whose
(
it

contains

“Bartech”
)
of

it
))

A:
Bartech Bartech 3.6.0 - 2013/09/23 15:30 - 2013/09/23 15:30 INSTALACION OK

T:
1.854 ms

(imported comment written by Dan_Spain)

awesome! Very well NoahSalzman, your solution fits perfect