yrahul3910 / pysh

Embed bash in your Python
MIT License
0 stars 0 forks source link

Add support for awk expressions #4

Closed yrahul3910 closed 1 year ago

yrahul3910 commented 1 year ago

One use case is counting the number of lines in a file containing an expression. Currently, the solution is:

import glob

for file in glob.glob('*.out'):
    count = `grep Running {file} | wc -l`.split()[0]
    print(f'{file} has {count} lines')

However, a better solution might be a full-Shell solution:

import glob

for file in glob.glob('*.out'):
    count = `grep Running {file} | wc -l | awk "{print $1}"`
    print(f'{file} has {count} lines')

Currently, the curly braces are recognized as part of an f-string as part of its transpiling.

yrahul3910 commented 1 year ago

Please use the Python 3 f-string syntax for escaping:

count = int`grep Running {file} | wc -l | awk "{{print $1}}"`