4 ms·
awk is also interesting because it's not just a language, it's a "model". It isn't something that you can't write with some lines of any other language but, bec
by dbolgheroni 8y ago
awk is also interesting because it's not just a language, it's a "model". It isn't something that you can't write with some lines of any other language but, because the loop is embedded, makes it easier to write utilities for the command line.
- ollysb 8y agoYou can get the loop behaviour with ruby $ echo -e $'line one\nline two' | ruby -ne 'puts $_.split(/\W+/)[1]' one two
- fl0wenol 8y agoruby's -n and -p options are venerable equivalents to perl's options which were present in version 1.0 waaay back in 1987 and they were there so it could be that drop in replacement for awk ruby inherited a lot of structure and ideas from perl which it inherited from awk and that thought makes me irrationally happy
- Too 8y agoYou can easily wrap python with a small script that makes it more useful as command line filtering tool. Most of the bloat actually just comes from importing packages. #!/usr/bin/python3 import re, sys, json, other, useful, packages def printf(s): print(s.format(**globals())) for NR, line in enumerate(sys.stdin): match = eval(sys.argv[1]) if match: eval(sys.argv[2]) Then you can use this in command line as somecommand | pyawk.py "re.search(r'^(pattern)\s(otherpattern)', line)" "printf('{NR}) {match[1]}')" I deliberately didn't pass pattern straight into re.search but rather provides the option to do other forms of parsing/matching in that argument, for example json parsing. I just spent 2 minutes writing this script so it's obviously not perfect and you probably won't be able to use it for json out of the box but give it a few more iterations and it will most likely work.