Re: convert script awk in python

2021-03-29 Thread Loris Bennett
Michael Torrie writes: > On 3/25/21 1:14 AM, Loris Bennett wrote: >> Does any one have a better approach? > > Not as such. Running a command and parsing its output is a relatively > common task. Years ago I wrote my own simple python wrapper function > that would make it easier to run a program

RE: convert script awk in python

2021-03-27 Thread pjfarley3
Many thanks for the link to that document. Most helpful. Peter > -Original Message- > From: Michael Torrie > Sent: Friday, March 26, 2021 8:32 PM > To: python-list@python.org > Subject: Re: convert script awk in python > > On 3/25/21 1:14 AM, Loris Bennett wrote:

RE: convert script awk in python

2021-03-26 Thread Avi Gross via Python-list
plit! ∀vi ∃. Grθß -Original Message- From: Python-list On Behalf Of 2qdxy4rzwzuui...@potatochowder.com Sent: Friday, March 26, 2021 9:43 PM To: python-list@python.org Subject: Re: convert script awk in python On 2021-03-26 at 21:06:19 -0400, Avi Gross via Python-list wrote: > A generat

Re: convert script awk in python

2021-03-26 Thread 2QdxY4RzWzUUiLuE
On 2021-03-26 at 21:06:19 -0400, Avi Gross via Python-list wrote: > A generator that opens one file at a time (or STDIN) in a consistent > manner, would be a reasonable thing to have as part of emulating AWK. https://docs.python.org/3/library/fileinput.html -- https://mail.python.org/mailman/li

RE: convert script awk in python

2021-03-26 Thread Avi Gross via Python-list
26, 2021 8:32 PM To: python-list@python.org Subject: Re: convert script awk in python On 3/25/21 1:14 AM, Loris Bennett wrote: > Does any one have a better approach? Not as such. Running a command and parsing its output is a relatively common task. Years ago I wrote my own simple python wrapper

Re: convert script awk in python

2021-03-26 Thread Michael Torrie
On 3/25/21 1:14 AM, Loris Bennett wrote: > Does any one have a better approach? Not as such. Running a command and parsing its output is a relatively common task. Years ago I wrote my own simple python wrapper function that would make it easier to run a program with arguments, and capture its out

Re: convert script awk in python

2021-03-26 Thread Pankaj Jangid
Christian Gollwitzer writes: > The closest equivalent I can come up with in Python is this: > > == > import sys > > s=0 > for line in sys.stdin: > try: > s += float(line.split()[1]) > except: > pass > print(s) > =

Re: convert script awk in python

2021-03-25 Thread Dan Ciprus (dciprus) via Python-list
s? -Original Message- From: Python-list On Behalf Of Cameron Simpson Sent: Tuesday, March 23, 2021 6:38 PM To: Tomasz Rola Cc: Avi Gross via Python-list Subject: Re: convert script awk in python On 23Mar2021 16:37, Tomasz Rola wrote: On Tue, Mar 23, 2021 at 10:40:01AM -0400, Avi Gro

Re: convert script awk in python

2021-03-25 Thread Loris Bennett
thought of calling 'xargs' via Popen, but this seemed very fiddly (I didn't manage to get it working) and anyway seemed a bit weird to me as it is really just a loop, which I can implement perfectly well in Python. Cheers, Loris >> seff_output = [] >>

Re: convert script awk in python

2021-03-25 Thread Peter Otten
all seems a bit laboured. Does any one have a better approach? Cheers, Loris -Original Message- From: Cameron Simpson Sent: Wednesday, March 24, 2021 6:34 PM To: Avi Gross Cc: python-list@python.org Subject: Re: convert script awk in python On 24Mar2021 12:00, Avi Gross wrote: Bu

Re: convert script awk in python

2021-03-25 Thread Christian Gollwitzer
Am 25.03.21 um 00:30 schrieb Avi Gross: It [awk] is, as noted, a great tool and if you only had one or a few tools like it available, it can easily be bent and twisted to do much of what the others do as it is more programmable than most. But following that line of reasoning, fairly simple pytho

Re: convert script awk in python

2021-03-25 Thread Loris Bennett
seff_output.append(str(line.strip(), "UTF-8")) ... but compared the to the bash pipeline, this all seems a bit laboured. Does any one have a better approach? Cheers, Loris > -Original Message- > From: Cameron Simpson > Sent: Wednesd

RE: convert script awk in python

2021-03-24 Thread Avi Gross via Python-list
- From: Cameron Simpson Sent: Wednesday, March 24, 2021 6:34 PM To: Avi Gross Cc: python-list@python.org Subject: Re: convert script awk in python On 24Mar2021 12:00, Avi Gross wrote: >But I wonder how much languages like AWK are still used to make new >programs as compared to a time

Re: convert script awk in python

2021-03-24 Thread Cameron Simpson
On 24Mar2021 12:00, Avi Gross wrote: >But I wonder how much languages like AWK are still used to make new >programs >as compared to a time they were really useful. You mentioned in an adjacent post that you've not used AWK since 2000. By contrast, I still use it regularly. It's great for proo

Re: convert script awk in python

2021-03-24 Thread Alan Gauld via Python-list
On 24/03/2021 16:00, Avi Gross via Python-list wrote: > But I wonder how much languages like AWK are still used to make new programs > as compared to a time they were really useful. True. I first discovered awk from a Byte article around 1988/9 and it became my goto tool for text munching right u

RE: convert script awk in python

2021-03-24 Thread Avi Gross via Python-list
n-list On Behalf Of Alan Gauld via Python-list Sent: Wednesday, March 24, 2021 5:28 AM To: python-list@python.org Subject: Re: convert script awk in python On 23/03/2021 14:40, Avi Gross via Python-list wrote: > $1 == 113 { > if (x || y || z) > print "More than one ty

Re: convert script awk in python

2021-03-24 Thread Alan Gauld via Python-list
On 23/03/2021 14:40, Avi Gross via Python-list wrote: > $1 == 113 { > if (x || y || z) > print "More than one type $8 atom."; > else { > x = $2; y = $3; z = $4; > istep++; > } > } > > I am a tod concerned as to where any of the variables x, y or z have been > d

RE: convert script awk in python

2021-03-24 Thread Avi Gross via Python-list
anslator by just saving some JSON descriptions? -Original Message- From: Python-list On Behalf Of Cameron Simpson Sent: Tuesday, March 23, 2021 6:38 PM To: Tomasz Rola Cc: Avi Gross via Python-list Subject: Re: convert script awk in python On 23Mar2021 16:37, Tomasz Rola wrote: >On Tue, M

Re: convert script awk in python

2021-03-23 Thread Cameron Simpson
On 23Mar2021 16:37, Tomasz Rola wrote: >On Tue, Mar 23, 2021 at 10:40:01AM -0400, Avi Gross via Python-list wrote: >[...] >> I am a tod concerned as to where any of the variables x, y or z have been >> defined at this point. I have not seen a BEGIN {...} pattern/action or >> anywhere these have be

Re: convert script awk in python

2021-03-23 Thread Tomasz Rola
On Tue, Mar 23, 2021 at 10:40:01AM -0400, Avi Gross via Python-list wrote: > Alberto, > [...] > I am a tod concerned as to where any of the variables x, y or z have been > defined at this point. I have not seen a BEGIN {...} pattern/action or > anywhere these have been initialized but they are set

RE: convert script awk in python

2021-03-23 Thread Avi Gross via Python-list
WiAH2CJIBAjE3mAEAoAEBq gEHZ3dzLXdperABCg&sclient=gws-wiz&ved=0ahUKEwjT7q2T0sbvAhUGpFkKHYwJAIAQ4dUDC Ak&uact=5 -Original Message- From: Python-list On Behalf Of alberto Sent: Tuesday, March 23, 2021 7:32 AM To: python-list@python.org Subject: convert script awk in python Hi

convert script awk in python

2021-03-23 Thread alberto
Hi to everyone I have an awk script that calculate minimum distances between points ## atom type frag - atom type surface #!/bin/bash FILE1=$1.lammpstrj if [ -f $FILE1 ]; then awk 'function sq(x) { return x * x; } function dist(x1, y1, z1, x2, y2, z2) { return sqrt(sq(x1 - x2) + sq(y1