Search Results

Search: Posts Made By: khoremand
4,747
Posted By ripat
For the reverse order, just pipe the output in...
For the reverse order, just pipe the output in tac:

awk '{w[length] = w[length] ? w[length]"\n"$0 : $0} END {for(l in w) print w[l]}' file | tac

length() is a awk function that output the,...
4,747
Posted By ripat
Nice trick for the reverse order! Edit: My...
Nice trick for the reverse order!

Edit:
My solution above does not return the expected result on large dictionaries. The w array gets out of sequence. Updated version inspired by Scrutinizer's...
4,747
Posted By Scrutinizer
Or, instead of tac, expanding on ripat's...
Or, instead of tac, expanding on ripat's suggestion:
awk '{l=length; if(l>m)m=l; w[l]=w[l] $0 RS} END{for(l=m;l>=1;l--) if(w[l])printf "%s",w[l]}' infile
4,747
Posted By ripat
awk oneliner alternative awk '{w[length] =...
awk oneliner alternative

awk '{w[length] = w[length] ? w[length]"\n"$0 : $0} END {for(l in w) print w[l]}' file
4,747
Posted By Yoda
This thread...
This thread (https://www.unix.com/shell-programming-scripting/101372-how-sort-strings-length.html) might help.

Note that for reverse order sorting you can use sort -nr
4,747
Posted By drl
Hi. The available utility msort allows a...
Hi.

The available utility msort allows a number of different comparison types, and among them is string length. Here's an example on a sample of dictionary data:
#!/usr/bin/env bash

# @(#)...
Showing results 1 to 6 of 6

 
All times are GMT -4. The time now is 05:33 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy