Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 6 down vote accepted

Try this:

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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