sort -k 1 Temp0706AR.txt > Temp0706AS.txt

As I have already told you many times, '-k 1' does not make any difference. It mean "sort the lines considering *everything starting with* the first field". You certainly mean '-k 1,1', which means "sort the lines considering *only* the first field".

That command behaves as documented. Properly using 'sort' is your problem. It is not sort that "has a problem": it cannot magically guess what you want. You have to tell it, using the proper options.

awk '{print $1,$2}' 'Temp0706AR.txt' | ...

That AWK program is useless: just give Temp0706AR.txt as an argument to the subsequent command.

... | sed 's/\./'\ '/g' | sort -k 3 | ...

Just specify '.' as sort's field separator.  'info sort' explains:
‘-t SEPARATOR’
‘--field-separator=SEPARATOR’
Use character SEPARATOR as the field separator when finding the sort keys in each line. By default, fields are separated by the empty string between a non-blank character and a blank character. By default a blank is a space or a tab, but the ‘LC_CTYPE’ locale can change this. That is, given the input line ‘ foo bar’, ‘sort’ breaks it into fields ‘ foo’ and ‘ bar’. The field separator is not considered to be part of either the field preceding or the field following, so with ‘sort -t " "’ the same input line has three fields: an empty field, ‘foo’, and ‘bar’. However, fields that extend to the end of the line, as ‘-k 2’, or fields consisting of a range, as ‘-k 2,3’, retain the field separators present between the endpoints of the range.

And, again, you probably mean '-k 3,3' rather than '-k 3'. Besides the specification of option -k, 'info sort' includes good examples such as: Sort numerically on the second field and resolve ties by sorting alphabetically on the third and fourth characters of field five. Use ‘:’ as the field delimiter.
          sort -t : -k 2,2n -k 5.3,5.4
Note that if you had written ‘-k 2n’ instead of ‘-k 2,2n’ ‘sort’ would have used all characters beginning in the second field and extending to the end of the line as the primary _numeric_ key. For the large majority of applications, treating keys spanning more than one field as numeric will not do what you expect. Also note that the ‘n’ modifier was applied to the field-end specifier for the first key. It would have been equivalent to specify ‘-k 2n,2’ or ‘-k 2n,2n’. All modifiers except ‘b’ apply to the associated _field_, regardless of whether the modifier character is attached to the field-start and/or the field-end part of the key specifier.

So in the end, I believe you only want:
$ sort -t . -k 3,3 Temp0706AR.txt > Temp0706AS.txt

... | awk '{print $1,$2,$3,$4,$5"\t"$6}' '-' | sed 's/'\ '/\./g' | awk '{print $1"\t"$2}' '-'

The two AWK programs are useless and there is unnecessary quoting and escaping in sed's substitution. In other terms, all that is equivalent to:
sed 's/ /./g'
But there is no good reason to use sed when tr applies:
tr ' ' '.'

Reply via email to