4 ms·
> To me that is the value. Interesting... to me the value (er, a value) is that you can write /PATTERN/ { print $3 } instead of import re, sys for lin
by mehrdadn 8y ago
> To me that is the value.
Interesting... to me the value (er, a value) is that you can write
/PATTERN/ { print $3 }
instead of
import re, sys
for line in sys.stdin:
if re.search('PATTERN', line):
print(line.split()[2])
And another value is that it's more likely to be preinstalled than Python.
- 3rdAccount 8y agoI think you misunderstand me as we might agree. Python is great for small to medium scripts, but can be verbose for the really small stuff that works better as a combination of Linux and Awk commands. Python has a lot of stuff in the standard library that I'm going to guess is missing from Awk (Sqlite, Sets, Classes...etc).
- mehrdadn 8y agoI guess the example I gave you was a one-liner but I didn't intend to constrain it to such. Just a week or two ago I wrote a 33-line script (that seems to fall squarely in your "small-to-medium" category) to calculate the minimal set of packages I need to install on Ubuntu in order to obtain the same set of packages I have right now. 28 of those 33 lines were an awk script consisting of three /PATTERN/{} blocks and one END{} block. It seemed about as simple as it could possibly be, and doing it in Python would've probably been twice as verbose.
- fireattack 8y agoDoes this python example actually work? What does line.split()[2] do?
- mehrdadn 8y agohttps://onlinegdb.com/SkTP0yfW7 https://onlinegdb.com/SkTP0yfW7
- fireattack 8y agoThanks. I thought /PATTERN/ { print $3 } is about to extract 3rd group of the regex.
- detaro 8y agoit splits line into substrings at spaces, and then selects the third substring.