2 ms·
The 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
by Someone 4y ago
The 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?)