I've got a column file like this:

1 1 1 AKSDFJADFKASDJFAK
2 1 1 ADKLCJASDLKCJDLACKADCJLKDACJADS
3 1 2 AKLJDFHALKDJFHLKJSDKSDFHAKJFDHAKFHJAKFJ

And I would like to sort the entries by the fourth column, with the longest word first. Any suggestions?

up vote 7 down vote accepted

Try this:

awk '{print $0" "length($4)}' infile | sort -k5,5rn | sed -e 's/ [0-9]*$//' > outfile

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.