i'm looking rearrange rows in text file(test.txt) based on last column having numbers.for example in below file see numbers 714,708,816,202,222 respectively last column.so want rearrange entire column in ascending order based on last column
wwwdev.comp.hello:443 hello, inc. valid may 20 2018 714 hostname cert expiry hidev.comp.hello:443 hello, inc. valid may 14 2018 708 hidev.comp.hello:443 hello, inc. valid -------------- gtdev.hello:443 hello, inc. valid aug 30 2018 816 wwwdev.hello:443 hello, inc. valid dec 24 2016 202 wwwdev.hello:443 hello, inc. valid dec 24 2016 222
expected o/p:
wwwdev.hello:443 hello, inc. valid dec 24 2016 202 hostname cert expiry wwwdev.hello:443 hello, inc. valid dec 24 2016 222 hidev.comp.hello:443 hello, inc. valid -------------- hidev.comp.hello:443 hello, inc. valid may 14 2018 708 wwwdev.comp.hello:443 hello, inc. valid may 20 2018 714 gtdev.hello:443 hello, inc. valid aug 30 2018 816
tried:
sort -k6 -n test.txt
please suggest.
note:i have skip rows without numbers , continue next row.
$ sort -n -k8 file wwwdev.hello:443 hello, inc. valid dec 24 2016 202 wwwdev.hello:443 hello, inc. valid dec 24 2016 222 hidev.comp.hello:443 hello, inc. valid may 14 2018 708 wwwdev.comp.hello:443 hello, inc. valid may 20 2018 714 gtdev.hello:443 hello, inc. valid aug 30 2018 816
if don't know how many columns there are, better decorate/sort/undecorate awk
.
$ awk '{print $nf "\t" $0}' file | sort -n -k1,1 | cut -f2-