[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Fwd: [Dicas-L]Justificador de texto com Sed
From: |
Diogo Florenzano Avelino |
Subject: |
Fwd: [Dicas-L]Justificador de texto com Sed |
Date: |
Mon, 31 Jul 2000 11:14:45 -0300 |
This is a forwarded message
From: Rubens Queiroz de Almeida #200503# <address@hidden>
To: address@hidden <address@hidden>
Date: Friday, July 21, 2000, 4:53:09 PM
Subject: [Dicas-L]Justificador de texto com Sed
===8<==============Original message text===============
Justificador de texto com Sed
---------------------------------------------------------------------
Colaboração: Aurélio Marinho Jargas [address@hidden]
Este script com sed para justificar texto é um verdadeiro
achado. Foi escrito pelo Aurélio Marinho, que inclusive mantém
uma lista de discussão sobre sed, onde já aprendi muita coisa
boa e interessante. Ressaltando, a mensagem do Aurélio eu peguei
da lista, da qual sou assinante. Pedi autorização a ele para
publicar na Dicas-L e para nossa sorte ele concordou :)
Para assinar a lista sed-br, basta enviar uma mensagem vazia
para o endereço address@hidden.
A seguir, a mensagem do Aurélio, já formatada com o script
justifica.sed:
---------------------------------------------------------------------
olás,
sexta à noite, hoje não rolou show ou náite, então a ociosidade
me fez ser produtivo &:)
aí nessa falta de algo de melhor pra fazer, fiz um carinha que
fazia tempo que eu queria, um justificador de texto.
não é perfeito, mas funciona. pega um texto já quebrado no número
limite de colunas e apenas inclui uns espaços em branco aqui e
ali, da esquerda para a direita, palavra por palavra, até atingir
o limite máximo de colunas (no caso 65, que é o que eu uso aqui
no pine).
se quiser usá-lo, basta:
prompt$ chmod +x justifica.sed
prompt$ ./justifica.sed arquivo.txt > arquivo-justificado.txt
se quiser alterar, o número de colunas máximo, troque todos os 65
do script pelo número desejado.
se quiser usar no vim, selecione o texto com o modo visual e
:'<,'>!justifica.sed
ah! esta mensagem foi justificada por ele &:)
justifica.sed
#!/bin/sed -f
# justify.sed
#
# it gets a text already wrapped on the desired number of columns
# and add extra white spaces, from left to right, word by word,
# to justify all the lines. there is a maximum of 5 spaces to be
# inserted between the words. if this limit is reached, the line
# is not justified (come on, more than 5 is horrible). empty
# lines are ignored. btw, this comments were justified with this
# script &:)
#
# 20000715 <address@hidden>
# we'll only justify lines with less than 65 chars
/^.\{65\}/!{
# cleaning extra spaces of the line
s/^ \+//
s/ \+/ /g
s/ \+$//
# don't try to justify blank lines
/^$/b
# backup of the line
h
# spaces -> pattern
# convert series of spaces to a internal pattern `n
:s2p
s/ /`5/g
s/ /`4/g
s/ /`3/g
s/ /`2/g
s/ /`1/g
t 1space
b
# pattern -> spaces
# restore the spaces converted to the internal pattern `n
:p2s
s/`5/ /g
s/`4/ /g
s/`3/ /g
s/`2/ /g
s/`1/ /g
t check
b
# check if we've reached our right limit
# if not, continue adding spaces
:check
/^.\{65\}/!b s2p
b
# here's the "magic":
# add 1 space to the first and minor internal pattern found.
# this way, the extra spaces are always added from left to right,
# always balanced, one by one.
# right after the substitution, we'll restore the spaces and
# test if our limit was reached.
:1space
s/`1/`2/ ; t p2s
s/`2/`3/ ; t p2s
s/`3/`4/ ; t p2s
s/`4/`5/ ; t p2s
# we don't want to justify with more than 5 added spaces between
# words, so let's restore the original line
/`5/x
}
---------------------------------------------------------------
As mensagens da lista Dicas-L são veiculadas diariamente
para 8896 assinantes.
Para sair ou assinar a lista Dicas-L, consulte o documento que
se encontra em http://www.Dicas-L.unicamp.br/FAQ.html.
A redistribuição desta e outras mensagens da lista Dicas-L pode
ser feita livremente, deste que o conteúdo, inclusive esta nota,
não sejam modificados.
---------------------------------------------------------------
===8<===========End of original message text===========
[]'s
[SLyDeR]
_______________________________________________
Diogo Florenzano Avelino <address@hidden>
Linux User: #158015 | ICQ UIN: #4102317
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Fwd: [Dicas-L]Justificador de texto com Sed,
Diogo Florenzano Avelino <=