Полезная информация

UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 36.2 Sort Fields: How sort Sorts Chapter 36
Sorting
Next: 36.4 Confusion with White Space Field Delimiters
 

36.3 Changing the Field Delimiter

Article 36.2 explained how sort separates a line of input into two or more fields using "white space" (spaces or tabs) as field delimiters. The -t option lets you change the field delimiter to some other character.

For example, if you wanted to sort the login names on your system by the login shell they use, you could issue a command like this:

/etc..wd 





% sort -t: +6 /etc/passwd
root:SndEKOs9H7YLm:0:1:Operator:/:/bin/csh
sys:*:2:2::/:/bin/csh
jim:LjKwcUt8l6kZK:2391:1004:Jim O'Callahan:/u/jim:/bin/csh
   ...
bart:2DPD8rCOKBbUu:2665:1004:Bart Buus:/u/bart:/bin/tcsh
tap:xY7oeuJ8WxyGO:2943:1004:Tap Bronman:/u/tap:/bin/tcsh

The option -t: tells sort to use a colon as a field separator - so, in this example, field 0 is the login name, field 1 is the encoded password, field 2 is the user ID number, field 3 is the group ID number, and so on. By this numbering, the login shell is in the sixth field.

Remember that sort numbers fields starting with zero - this will save you lots of grief. Two consecutive colons indicate a "null" field that still must be counted.

- ML, TOR


Previous: 36.2 Sort Fields: How sort Sorts UNIX Power ToolsNext: 36.4 Confusion with White Space Field Delimiters
36.2 Sort Fields: How sort Sorts Book Index36.4 Confusion with White Space Field Delimiters

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System