3 ms·
if you used a regex to match a line, would it run slower than just via the field separator, and count the NF? On a tiny file the speed won't matter at all - bu
by chii 4y ago
if you used a regex to match a line, would it run slower than just via the field separator, and count the NF?
On a tiny file the speed won't matter at all - but on a big file (let's say, you're looking thru log files with hundreds of gigs in size).
- Someone 4y agoThe regex solution might be faster. The $0=$2 solution has to find the second field and test it for truthiness for every line, while the regex one only has to do that for those matching the regex, and matching that regex will be fast for most lines (skipping spaces and then testing for a fixed string ‘name’ is easy) Regardless, the regex solution is more robust and maintainable. Depending on how this get used, I might add code to detect the ‘appVersion’ start and end lines, set/clear a flag there and only match the ‘name’ lines when that flag is set to make it even more robust (who knows what other lines might contain ‘name’ now or in the future?)