[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]

Re: bash script



On Mon, Feb 19, 2001 at 08:56:25PM +0530, Binand Raj S. wrote:
> Maybe I should rewrite the whole thing in perl? :-)

Yes, you probably should. Will be faster - avoiding a large number
of forks.

Since I don't want to fill up precious RAM in my head with perl syntax,
I use python, but envy all the good perl one liners. So I came up with
cpy (command line python): 

#!/usr/bin/env python

from string import *
import sys
import fileinput

command = reduce(lambda x, y: x + ' ' + y, sys.argv[1:])
# Construct a lambda func out of command
command = "lambda line: " + command
sys.argv = []
for line in fileinput.input():
    global fields
    line = strip(line)
    fields = split(line)
    print apply(eval(command), [line])


$ cat /etc/passwd | cpy 'upper(line)'

	-Arun