coreutils: Working with fields

1 
1 8.3.3 Working with fields
1 -------------------------
1 
1 Use ‘-1’,‘-2’ to set the key fields for each of the input files.  Ensure
1 the preceding ‘sort’ commands operated on the same fields.
1 
1 The following example joins two files, using the values from seventh
1 field of the first file and the third field of the second file:
1 
1      $ sort -k 7b,7 file1 > file1.sorted
1      $ sort -k 3b,3 file2 > file2.sorted
1      $ join -1 7 -2 3 file1.sorted file2.sorted > file3
1 
1 If the field number is the same for both files, use ‘-j’:
1 
1      $ sort -k4b,4 file1 > file1.sorted
1      $ sort -k4b,4 file2 > file2.sorted
1      $ join -j4    file1.sorted file2.sorted > file3
1 
1 Both ‘sort’ and ‘join’ operate of whitespace-delimited fields.  To
1 specify a different delimiter, use ‘-t’ in _both_:
1 
1      $ sort -t, -k3b,3 file1 > file1.sorted
1      $ sort -t, -k3b,3 file2 > file2.sorted
1      $ join -t, -j3    file1.sorted file2.sorted > file3
1 
1 To specify a tab (ASCII 0x09) character instead of whitespace, use (1):
1 
1      $ sort -t$'\t' -k3b,3 file1 > file1.sorted
1      $ sort -t$'\t' -k3b,3 file2 > file2.sorted
1      $ join -t$'\t' -j3    file1.sorted file2.sorted > file3
1 
1 If ‘join -t ''’ is specified then the whole line is considered which
1 matches the default operation of sort:
1 
1      $ sort file1 > file1.sorted
1      $ sort file2 > file2.sorted
1      $ join -t'' file1.sorted file2.sorted > file3
1 
1    ---------- Footnotes ----------
1 
1    (1) the ‘$'\t'’ is supported in most modern shells.  For older
1 shells, use a literal tab
1