awk 또는 sed를 사용하여 열에서 삭제하는 방법\n

awk 또는 sed를 사용하여 열에서 삭제하는 방법\n

나는 데이터를 가지고 있습니다 :

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

가능하다면 sed나 awk를 사용하여 4열의 \n을 제거하고 싶습니다. 결과는 다음과 같습니다.

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

\n 이전 패턴은 항상 다릅니다. 1-9 또는 텍스트이거나 , :, ;(기타 기호 일 수 있습니다 ).

텍스트가 변경되었지만 형식은 원본 데이터와 동일합니다.

답변1

sed- 줄에 파이프가 아닌 문자만 포함된 경우 이전 줄에 연결합니다.

sed -e :a -e '$!N; s/\n\([^|]*\)$/ \1/; 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

답변2

Awk해결책:

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

관련 정보