Artificial intelligent assistant

Sort lines by number of words per line Given input: hello: world foo bar baz bar: baz: bin boop bop fiz bang beep bap: bim bam bop boatkeeper: poughkeepsie I would like to sort it into most words at the top, to least at the end, like so: baz: bin boop bop fiz bang beep hello: world foo bar baz bap: bim bam bop boatkeeper: poughkeepsie bar: How would I do this with `sort` or some other tool?

You could do something like:


awk '{print NF,$0}' file | sort -nr | cut -d' ' -f 2-


We use `awk` to prefix the number of fields to each line. We then `sort` by that number and remove it with `cut`.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 57858c4c71131950fcfb6edff11b64e8