Looking for an algorithm that cancels the output of the sprintf () function

I am working on a project that requires analysis of log files. I am looking for a quick algorithm that will receive group messages as follows:

The temperature at P1 is 35F.

The temperature at P1 is 40F.

The temperature at P3 is 35F.

Logger is stopped.

Logger is running.

The temperature at P1 is 40F.

and produces something in the form of printf ():

"The temperature at P%d is %dF.", Int1, Int2" 
{(1,35), (1, 40), (3, 35), (1,40)}

The algorithm should be general enough to recognize almost any data load in message groups.

I tried to search for this technology, but I don’t even know the right conditions for the search.

+3
source share
10 answers

Overview:

A !! , , .

:




:

Column 1: {The: 4}
Column 2: {car: 1, cat: 1, dog: 1, moon: 1}
Column 3: {jumped: 4}
Column 4: {over: 4}
Column 5: {the: 4}
Column 6: {moon: 4}

, , (6).

, , .

  • : , .
  • : , , , , . /[a-z]+/i.
  • : , # 1; , .
  • : , # 1; , .
  • moon: , # 1; , .

, , :

/The ([a-z]+?) jumps over the moon/

:

  • , , , .

  • , ( ) - -.

  • , , , .

+6

, fscanf() sscanf(). fprintf() sprintf().

+12

. , . . . , :

1: 30000

2: K2 28000

= > ? = > :

[name] is [number] feet high

. , , .

. "". . .

, , .

+3

, , - sprintf(), . , , .

+2

, , , , . .

- , , . , "123.456" ? "123 456"? "35F" "F", 0x35F? -, , . , sscanf, -, - .

, , . , . - (Perl):

my @vals = ();
while (defined(my $line = <>))
{
    if ($line =~ /The temperature at P(\d*) is (\d*)F./)
    {
        push(@vals, "($1,$2)");
    }
}
print "The temperature at P%d is %dF. {";
for (my $i = 0; $i < @vals; $i++)
{
    print $vals[$i];
    if ($i < @vals - 1)
    {
        print ",";
    }
}
print "}\n";

isL

The temperature at P%d is %dF. {(1,35),(1,40),(3,35),(1,40)}

- , . , .

+1

- . , , , , .

. , , .

20 10000 + .

"", "The temperature at P[1-3] is [0-9]{2}F.". , , "":

.

Logger.

"Logger (.+).".

, .

+1

@John: , , "" . *scanf , , .

0

@Derek Park: , .

, :

  1. ,
  2. , . (.. [pattern: 1] [junk] [pattern: 2])

edit-distance. .

, , , , !

0

@Anders

, , .

, . , "35F" - , . , . , , ( ).

, , .:)

0

http://www.logparser.com IIS, . Gabriele Giuseppini " -". , Amazon Marketplace - 16 . dead-tree .

, " MS Log Parser, Log Parser Lizard" http://www.lizardl.com/.

The key problem, of course, is the complexity of your GRAMMAR. To use any kind of log parser, since this term is usually used, you need to know exactly what you are viewing, you can write BNF for it. Many years ago, I took a course based on the Book of Dragons of Aho-Ullman, and the carefully understood LALR technology can give you optimal speed, if, of course, you have this CFG.

On the other hand, it looks like you might have achieved something like AI-like, which is completely different from complexity.

0
source

Source: https://habr.com/ru/post/1696408/


All Articles