[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [shell-script] sed expressao regular
From: |
Paulo Bettega |
Subject: |
Re: [shell-script] sed expressao regular |
Date: |
Sun, 03 Aug 2014 02:18:44 -0300 |
User-agent: |
Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Thunderbird/31.0 |
Entendi como o Itamar e Alysson, substituir a primeira linha 'valor 1' pelas
outras.
sed '1,/valor 1/ {/valor 1/ s/.*/valor 1 = 2345\
valor 2 = asdf\
valor 3 = zxcv/}' <<<'texto1.1 {
texto 1.2 {
valor 1 = 1234
}
}
texto2.1 {
texto2.2 {
valor 1 = 1234
}
}'
Com o comando c não consegui escapar a chave que fecha o grupo de comandos,
só funcionou quebrando a linha, sem colocar barra no final (deve ser isso
que está escrito no 'info sed', acho que eu não entendi direito).
`c\'
`TEXT'
Delete the lines matching the address or address-range, and output
the lines of text which follow this command (each but the last
ending with a `\', which are removed from the output) in place of
the last line (or in place of each line, if no addresses were
specified). A new cycle is started after this command is done,
since the pattern space will have been deleted.
sed '1,/valor 1/ {/valor 1/ c\valor 1 = 2345\
valor 2 = asdf\
valor 3 = zxcv
}' <<<'texto1.1 {
texto 1.2 {
valor 1 = 1234
}
}
texto2.1 {
texto2.2 {
valor 1 = 1234
}
}'
Abraços Paulo Bettega
On 02-08-2014 22:14, 'edmarcos.souza' address@hidden [shell-script] wrote:
Depois de muitas pesquisas, não obtive o sucesso.
Consultei os sites
http://fahdshariff.blogspot.com.br/2012/12/sed-mutli-line-replacement-between-two.html
http://www.grymoire.com/Unix/Sed.html
mas nao consegui.
O que eu queria fazer com o sed é editar textos com o seguinte padrão:
# -----------------------------------
texto1.1 {
texto 1.2 {
valor 1 = 1234
}
}
texto2.1 {
texto2.2 {
valor 1 = 1234
}
}
# ---------------------------------
para
# -----------------------------------
texto1.1 {
texto 1.2 {
valor 1 = 2345
valor 2 = asdf
valor 3 = zxcv
}
}
texto2.1 {
texto2.2 {
valor 1 = 1234
}
}
Toda ajuda é bem vinda... obrigado