Statement in line action not working
elgow opened this issue · 3 comments
When I try to use a statement in the line action of pawk I get a syntax error. To reproduce just run a line taken direct from the README of pawk
pawk -B c=0 -E c 'c += os.stat(f[0]).st_size'
This results in this error:
File "/usr/local/lib/python2.7/site-packages/pawk.py", line 41, in _compile
self._codeobj = compile(self.cmd, 'EXPR', 'exec' if statement else 'eval')
File "EXPR", line 1
c += os.stat(f[0]).st_size
^
SyntaxError: invalid syntax
Any statement using "=" in the line action fails similarly. Statements seem to work in -B and -E actions, but only expressions work for line actions.
This is under python 2.7.5. Pawk does not report a version.
I'm not sure what's going on there, but it works for me with Python 2.7.11 and Pawk HEAD.
[alec@cavern:~]python -V
Python 2.7.11
[alec@cavern:~]ls | pawk -B c=0 -E c 'c += os.stat(f[0]).st_size'
60878
If you are using the version from PyPi you'll need to use the -s
flag to treat the expression as a statement. If you install from git it should "just work".
I've just pushed 0.6 which should let your line work as-is.
I was using the PyPi version, so that explains it. Thank you for pushing the update.
Also, thank you for pawk. It's very nice not to have to look up awk syntax whenever I need to do even marginally sophisticated line processing.