Reputation: 27
Here's a sample of what I have in a log file:
p1-OST001e oss031
p1-OST001f oss032
p1-OST0020 oss033
p1-OST0021 oss034
p1-OST0022 oss035
p1-OST0023 oss036
p1-OST0024 oss037
p1-OST0025 oss038
p1-OST0026 oss039
p1-OST0027 oss040
p1-OST0028 oss031
I want to sort it so the 2 OSTs match up with the oss ie.
p1-OST001e oss031
p1-OST0028 oss031
p1-OST001f oss032
etc
would be together.
Upvotes: 0
Views: 82
Reputation: 289565
You can use:
$ sort -t' ' -nk2.4 file
p1-OST001e oss031
p1-OST0028 oss031
p1-OST001f oss032
p1-OST0020 oss033
p1-OST0021 oss034
p1-OST0022 oss035
p1-OST0023 oss036
p1-OST0024 oss037
p1-OST0025 oss038
p1-OST0026 oss039
p1-OST0027 oss040
-t' '
sets space as field separator-n
sets numeric sort-k2.4
sets column 2 to be the index to sort by. With .4
we indicate to sort from the 4th character.Upvotes: 1