A következő címkéjű bejegyzések mutatása: regexp. Összes bejegyzés megjelenítése
A következő címkéjű bejegyzések mutatása: regexp. Összes bejegyzés megjelenítése

2021. február 1., hétfő

batchgrep: how to match many regexps 25x faster!

I came across a situation where I had to look for 1100+ regexps in a large file.
Running grep 1100 times is trivial but slow: took 5+ minutes (using MSYS2 on Windows 10) which is kind of unacceptable in my build scenario.

So I came up with the below script that will merge as many regexp patterns in one run of grep as your platform allows (32000 on cygwin / Windows, 131072 on Linux)

TL;DR: the same amount of pattern matching now takes 10-12 seconds, which is 25 times faster!😎

(n.b: I know dividing by the longest line is not using all the possible length, but is safer this way and the further speed gain was not worth a more complex solution for me)

2012. december 16., vasárnap

How to match unicode characters?

Lately I have been digging through scraped movie information pages with grep, trying to extract information.
I was surprised to find, that '.*' in a regexp just does not match 'Castillos de cartón' (yes, that is a movie suggestion as well. :)
After some testing I saw that matching brakes at the accented character being actually represented in two bytes. After some digging I have found the solution at: http://www.regular-expressions.info/unicode.html
To sum it all up you will need a perl regexp, where \X is the unicode version of the dot, so instead of:

grep 'class="blackbigtitle">.*' 135428/.porthu.html

you should use:

grep -P 'class="blackbigtitle">\X*' 135428/.porthu.html

And that is all, folks! :)

Rendszeres olvasók