I am conducting a text-based log analysis (fluentd), and I am considering using grep for the desk examination.
Eventually, I checked the difference in the processing method when registering Fluentd.
In case of /, process A
②Action B
for
If none, process C
処理Processing C may not contain any strings.
In this case, I think awk or sed can save process C with ".*". (I'm sorry if I'm wrong at this point)
What are the conditions for ruby?I looked up some reference sites, but I was even more confused.
I'm sorry, but I appreciate your cooperation.
ruby regular-expression fluentd grep
Answer only for "regular expressions that match everything".(I don't know about Fluentd, so I don't know if it's appropriate to use a "regular expression that matches everything" to express "if it's none of them")
Ruby also applies to .*
, but other than that, ^
and an empty string (this is also one of the regular expressions).It also depends on the regular expression engine and the processing system that uses it, but generally the most efficient of them is the empty string, followed by the ^
, and the least efficient is the .*
.
If it's Ruby, you'll find out by doing the following.(Depending on the environment, it will take a few minutes)
#!/bin/sh
time ruby-e'x="foo"; 1000000000.times {x=~//}'
time ruby-e'x="foo"; 1000000000.times {x=~/^/}'
time ruby-e'x="foo"; 1000000000.times {x=~/.*/}'
By the way, .*
is extremely slow for sed
(1), and there seems to be no way to specify an empty string.(\(\)
is applicable, but it is also slower than ^
.GNUsed Survey)
© 2024 OneMinuteCode. All rights reserved.