Is it possible to get the same result in one sort?

Hi,

This is the file that I want to sort:

$: cat files.tmp
1237008222      10664   log.10
1237008222      10664   log.12
1237008222      10664   log.14
1237008222      10664   log.16
1237008222      10664   log.18
1237008222      10664   log.2
1237008222      10664   log.4
1237008222      10664   log.6
1237008222      10664   log.8
2296620157      10696   log.1
2296620157      10696   log.11
2296620157      10696   log.13
2296620157      10696   log.15
2296620157      10696   log.17
2296620157      10696   log.3
2296620157      10696   log.5
2296620157      10696   log.7
2296620157      10696   log.9

The desired output is as below:

1237008222      10664   log.2
1237008222      10664   log.4
1237008222      10664   log.6
1237008222      10664   log.8
1237008222      10664   log.10
1237008222      10664   log.12
1237008222      10664   log.14
1237008222      10664   log.16
1237008222      10664   log.18
2296620157      10696   log.1
2296620157      10696   log.3
2296620157      10696   log.5
2296620157      10696   log.7
2296620157      10696   log.9
2296620157      10696   log.11
2296620157      10696   log.13
2296620157      10696   log.15
2296620157      10696   log.17

Currently, I have had to loop thru files.tmp and grep for lines containing field 1 and run it thru sort.

$: cat files.tmp | grep "^1237008222" | sort -t. -n -k2
1237008222      10664   log.2
1237008222      10664   log.4
1237008222      10664   log.6
1237008222      10664   log.8
1237008222      10664   log.10
1237008222      10664   log.12
1237008222      10664   log.14
1237008222      10664   log.16
1237008222      10664   log.18
$: cat files.tmp | grep "^2296620157" | sort -t. -n -k2
2296620157      10696   log.1
2296620157      10696   log.3
2296620157      10696   log.5
2296620157      10696   log.7
2296620157      10696   log.9
2296620157      10696   log.11
2296620157      10696   log.13
2296620157      10696   log.15
2296620157      10696   log.17

I thought the following should have done the trick but no.

$: cat files.tmp | sort -k1 | sort -t. -k2n
2296620157      10696   log.1
1237008222      10664   log.2
2296620157      10696   log.3
1237008222      10664   log.4
2296620157      10696   log.5
1237008222      10664   log.6
2296620157      10696   log.7
1237008222      10664   log.8
2296620157      10696   log.9
1237008222      10664   log.10
2296620157      10696   log.11
1237008222      10664   log.12
2296620157      10696   log.13
1237008222      10664   log.14
2296620157      10696   log.15
1237008222      10664   log.16
2296620157      10696   log.17
1237008222      10664   log.18

I can't find an example of the kind of sorting that am after. It is to sort on the first column and then the third column 'grouped' based on the first column as a set. :frowning:

At the moment, I am using a shell script and grep'ing for field1 and then doing the sort.

Try

sort  -t. -k1,1 -k2n file