sections in this module City College of San Francisco - CS160B
Unix/Linux Shell Scripting
Module: Unix Review
module list

sort

You should be familiar with sort. If, however, you are used to the old-fashioned sort key syntax of +N and -N, you must switch to the newer POSIX-style key syntax using -kN. The old key syntax has been deprecated for some time and is no longer supported on the linux version of sort.

POSIX-standard sort keys are indicated using the -kkeyspec syntax where keyspec is start[,stop][opts] where fields and characters are numbered beginning at 1.

start is field[.char] if .char is missing, the first character is indicated

stop is field[.char] if .char is missing, the end of the field is indicated. If stop is missing, the end of the key is the end of the record. 

Thus, -k2,2 indicates sort on field 2 only. 

The most common options to use are n (numeric) and r (reverse). 

Let's practice by interpreting a few sort keys:

-k2,2r  - perform an alphabetic sort on field 2 (only) in reverse (largest to smallest) order

-k3.2,3n - perform a numeric sort starting at the second character in field 3 (skip the first character). The key ends at the end of field 3 (or when there are no more numeric characters)

-k2,2n -k3r - perform a numeric sort on field 2 (only). Then break ties by an alphabetic sort beginning with field 3 and ending with the end of the record, in reverse order.

Preview question: Do you know what the problem with this command is?
scp you1@hills.ccsf.edu:~ ~/backup
If not, you should read the next section.

Prev This page was made entirely with free software on linux:  
Kompozer
and Openoffice.org    
Next

Copyright 2009 Greg Boyd - All Rights Reserved.

Document made with Kompozer