Re: Mimick tac with python.

2016-01-30 Thread Terry Reedy
On 1/30/2016 1:03 AM, Christian Gollwitzer wrote: Am 30.01.16 um 05:58 schrieb Random832: On Fri, Jan 29, 2016, at 23:46, Hongyi Zhao wrote: awk '{a[NR]=$0} END {while (NR) print a[NR--]}' input_file perl -e 'print reverse<>' input_file Well, both of those read the whole file into memory - ta

Re: Mimick tac with python.

2016-01-30 Thread Jussi Piitulainen
Christian Gollwitzer writes: > Am 30.01.16 um 05:58 schrieb Random832: >> On Fri, Jan 29, 2016, at 23:46, Hongyi Zhao wrote: >>> awk '{a[NR]=$0} END {while (NR) print a[NR--]}' input_file >>> perl -e 'print reverse<>' input_file >> >> Well, both of those read the whole file into memory - tac is so

Re: Mimick tac with python.

2016-01-30 Thread Christian Gollwitzer
Am 30.01.16 um 08:56 schrieb Jussi Piitulainen: Christian Gollwitzer writes: Am 30.01.16 um 05:58 schrieb Random832: On Fri, Jan 29, 2016, at 23:46, Hongyi Zhao wrote: awk '{a[NR]=$0} END {while (NR) print a[NR--]}' input_file perl -e 'print reverse<>' input_file Well, both of those read th

Re: Mimick tac with python.

2016-01-30 Thread Peter Otten
Christian Gollwitzer wrote: > Am 30.01.16 um 05:58 schrieb Random832: >> On Fri, Jan 29, 2016, at 23:46, Hongyi Zhao wrote: >>> awk '{a[NR]=$0} END {while (NR) print a[NR--]}' input_file >>> perl -e 'print reverse<>' input_file >> >> Well, both of those read the whole file into memory - tac is som

Re: Mimick tac with python.

2016-01-29 Thread Random832
On Fri, Jan 29, 2016, at 23:46, Hongyi Zhao wrote: > Hi all, > > I can use the following methods for mimicking tac command bellow: > > awk '{a[NR]=$0} END {while (NR) print a[NR--]}' input_file > perl -e 'print reverse<>' input_file Well, both of those read the whole file into memory - tac is so

Mimick tac with python.

2016-01-29 Thread Hongyi Zhao
Hi all, I can use the following methods for mimicking tac command bellow: awk '{a[NR]=$0} END {while (NR) print a[NR--]}' input_file perl -e 'print reverse<>' input_file Is it possible to do the same thing with python? Regards -- .: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :

Re: Mimick tac with python.

2016-01-29 Thread Hongyi Zhao
On Fri, 29 Jan 2016 23:58:38 -0500, Random832 wrote: > python <(echo 'import sys;print("".join(reversed(list(sys.stdin') Why do you write it as follows: cat input_file | python -c 'import sys;print("".join(reversed(list (sys.stdin' Regards -- .: Hongyi Zhao [ hongyi.zhao AT gmail.com ]

Re: Mimick tac with python.

2016-01-29 Thread Christian Gollwitzer
Am 30.01.16 um 05:58 schrieb Random832: On Fri, Jan 29, 2016, at 23:46, Hongyi Zhao wrote: awk '{a[NR]=$0} END {while (NR) print a[NR--]}' input_file perl -e 'print reverse<>' input_file Well, both of those read the whole file into memory - tac is sometimes smarter than that, but that makes fo

Re: Mimick tac with python.

2016-01-29 Thread Chris Angelico
On Sat, Jan 30, 2016 at 3:46 PM, Hongyi Zhao wrote: > I can use the following methods for mimicking tac command bellow: > > awk '{a[NR]=$0} END {while (NR) print a[NR--]}' input_file > perl -e 'print reverse<>' input_file > > Is it possible to do the same thing with python? python -c 'import sys;