If it is UNIX:
sort -k 2 file.txt
You can use multiple -k flags to sort more than one column. For example, to sort by last name, and then first as a constraint constraint:
sort -k 2,2 -k 1,1 file.txt
Relevant options from "man sort":
-k, --key = POS1 [, POS2]
run the key in POS1, put it on POS2 (start 1)
POS - F [.C] [OPTS], where F is the field number and C is the character position in the field. OPTS is one or more one-letter order options that override the global order parameters for this key. If no key is specified, use the entire string as the key.
-t, --field-separator = SEP
use SEP instead of a non-empty null transition
John Kugelman Nov 24 '10 at 1:19 2010-11-24 01:19
source share