Como remover \ n de uma coluna usando awk ou sed

1

Eu tenho dados:

1528198031|Andr|thund|Lorem ipsum dolor sit amet, consectetur adipiscing elit
1528202225|Andr|thund|Lorem ipsum dolor sit amet, conse
1) Lorem ipsum dolor sit amet, consectetur adipiscing elit
2) Lorem ipsum dolor sit amet, consectetur adipiscing elit
3) Lorem ipsum dolor sit amet, consectetur adipiscing elit

Lorem ipsum dolor sit amet, consectetur adipiscing elitLorem ipsum dolor sit amet, consectetur adipiscing elit
1528202574|Andr|thund|Lorem ipsum dolor sit amet, consectetur adipiscing elit
1528203825|Andr|thund|Lorem ipsum dolor sit amet, consectetur adipiscing elit
1528203890|Andr|rail|Lorem ipsum dolor sit amet, consectetur adipiscing elit

Eu quero remover \ n na coluna 4 usando sed ou awk, se possível. Resultado ficaria assim:

1528198031|Andr|thund|Lorem ipsum dolor sit amet, consectetur adipiscing elit
1528202225|Andr|thund|Lorem ipsum dolor sit amet, conse 1) Lorem ipsum dolor sit amet, consectetur adipiscing elit 2) Lorem ipsum dolor sit amet, consectetur adipiscing elit 3) Lorem ipsum dolor sit amet, consectetur adipiscing elit Lorem ipsum dolor sit amet, consectetur adipiscing elitLorem ipsum dolor sit amet, consectetur adipiscing elit
1528202574|Andr|thund|Lorem ipsum dolor sit amet, consectetur adipiscing elit
1528203825|Andr|thund|Lorem ipsum dolor sit amet, consectetur adipiscing elit
1528203890|Andr|rail|Lorem ipsum dolor sit amet, consectetur adipiscing elit

Padrões anteriores \ n sempre diferentes, podem ser de 1 a 9 ou texto, ou símbolos como : , ; , ( , ) .

O texto foi alterado, mas a formatação é como nos dados originais.

    
por Strawberry Hat 13.06.2018 / 21:11

2 respostas

2

sed - junte-se à linha anterior se esta linha contiver apenas caracteres não pipe:

sed -e :a -e '$!N; s/\n\([^|]*\)$/ /; ta' -e 'P;D' file
1528198031|Andr|thund|Lorem ipsum dolor sit amet, consectetur adipiscing elit
1528202225|Andr|thund|Lorem ipsum dolor sit amet, conse 1) Lorem ipsum dolor sit amet, consectetur adipiscing elit 2) Lorem ipsum dolor sit amet, consectetur adipiscing elit 3) Lorem ipsum dolor sit amet, consectetur adipiscing elit  Lorem ipsum dolor sit amet, consectetur adipiscing elitLorem ipsum dolor sit amet, consectetur adipiscing elit
1528202574|Andr|thund|Lorem ipsum dolor sit amet, consectetur adipiscing elit
1528203825|Andr|thund|Lorem ipsum dolor sit amet, consectetur adipiscing elit
1528203890|Andr|rail|Lorem ipsum dolor sit amet, consectetur adipiscing elit
    
por 13.06.2018 / 21:39
0

Awk solução:

awk -F'|' '{ printf "%s%s", (NR == 1? "" : (NF > 1? ORS : OFS)), $0 }
           END{ print "" }' file

A saída:

1528198031|Andr|thund|Lorem ipsum dolor sit amet, consectetur adipiscing elit
1528202225|Andr|thund|Lorem ipsum dolor sit amet, conse 1) Lorem ipsum dolor sit amet, consectetur adipiscing elit 2) Lorem ipsum dolor sit amet, consectetur adipiscing elit 3) Lorem ipsum dolor sit amet, consectetur adipiscing elit  Lorem ipsum dolor sit amet, consectetur adipiscing elitLorem ipsum dolor sit amet, consectetur adipiscing elit
1528202574|Andr|thund|Lorem ipsum dolor sit amet, consectetur adipiscing elit
1528203825|Andr|thund|Lorem ipsum dolor sit amet, consectetur adipiscing elit
1528203890|Andr|rail|Lorem ipsum dolor sit amet, consectetur adipiscing elit
    
por 13.06.2018 / 21:33