csh :t modifier (Was Re: basename(1) (Was Re:argv[0] in shellscript?))
Leo de Wit
leo at philmds.UUCP
Sun Jun 26 04:16:11 AEST 1988
In article <709 at ubu.warwick.UUCP> maujd at warwick.UUCP (Geoff Rimmer) writes:
> [other stuff deleted]...
>cat /etc/passwd | sed "s/:[^:]*:[^:]*:[^:]*:/ /" | sed "s/[,:].*//" | sort
> ^^TAB^^
>---------------------------------------------------------------------
> (BTW, anyone got any improvements on this 'sed' line?)
>---------------------------------------------------------------------
You COULD of course use awk (using IFS) ...
but, assuming you're as devoted a sed worshipper as I am, yes, I've got
an improvement:
Don't use the cat; sed can open the file or even the shell can open it for
sed (saves a process).
Don't use sed twice; one is just as good (even faster).
So the result is:
sed -e "s/:[^:]*:[^:]*:[^:]*:/ /" -e "s/[,:].*//" /etc/passwd | sort
Now maybe even the sed could be improved upon ...?
Leo.
More information about the Comp.unix.questions
mailing list