Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have the following CSV, separated by "|".

101|abc|this is desc|2017
102|xyz|"thie is a long desc
des for xyz continue here."|2017

I have two records, 101 and 102. 102 record is divided into 2 lines. How can I used sed or other command line tools to escape the new line character with "/"?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
284 views
Welcome To Ask or Share your Answers For Others

1 Answer

awk is better tool to handle this.

Assuming you know how many columns are needed in each line. You can use this awk command:

awk -v n=4 -F '|' 'p+NF<n{p+=NF-1; print $0 ""; next} {p=0} 1' file

101|abc|this is desc|2017
102|xyz|"this is a long desc
des for xyz continue here."|2017

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...