Pergunta

Estou usando:

cat this_file | sed ':a;N;$!ba;s/\n[a-z]/ [a-z]/g' > that_file

Texto de amostra:

However the text \n
looks like this when it replaces the newline.\n

Saída:

However the text [a-z]ooks like this when it replaces the newline.\n

Como isso é chamado?Alguma sugestão sobre o que estou fazendo de errado?

Foi útil?

Solução

Dentro do padrão, [a-z] denota uma classe de personagem.Dentro da substituição, é substituído como é.Você precisa usar uma referência anterior:

cat this_file | sed ':a;N;$!ba;s/\n\([a-z]\)/ \1/g' > that_file

Além disso, você poderia evitar o uso inútil de cat:

sed ':a;N;$!ba;s/\n\([a-z]\)/ \1/g' this_file > that_file
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top