Usando os mesmos princípios que os outros (obtenha o tamanho da linha, com e sem caracteres de espaço em branco, classifique-os e, em seguida, remova-os), mas com awk
:
awk '{NC = length(gensub(/[[:space:]]/, "", "g")); print length, NC, $0}' file |
sort -nk1,2 |
sed -r 's/^([0-9]+ ){2}//'
gensub(/[[:space:]]/, "", "g")
exclui todos os caracteres de espaços em branco na linha e, em seguida, obtemos o tamanho da string restante
Usando o texto da pergunta até o bloco de códigos, dobrado para 80 caracteres de largura:
$ awk '{NC = length(gensub(/[[:space:]]/, "", "g")); print length, NC, $0}' foo | sort -nk1,2 | sed -r 's/^([0-9]+ ){2}//'
increasing order).
Here's what I've got so far:
f the idiosyncrasies of bash.
iven a bunch of lines from STDIN, sort them first by the length of the line in i
I've tried this a couple of different ways but I usually get caught up in some o
, sort them by the number of nonblank characters contained in the lines (also in
I am working on learning bash scripting but I am struggling with this problem. G
ncreasing order. Then, if there are any lines with the same number of characters