sampat kumar
sampat kumar

Reputation: 31

Appending data in single line by removing junk character

I have data in particular format, Where my data is breaking with the lines after a + character and I need in a single line

INPUT:

   ABC|def|ghi+
   |jkl|mno
   XYZ|pqr|lmn+
   |qrr|stv

EXPECTED OUTPUT:

ABC|def|ghi|jkl|mno
XYZ|pqr|lmn|qrr|stv

Upvotes: 0

Views: 29

Answers (1)

glenn jackman
glenn jackman

Reputation: 247012

Here's a technique with awk:

awk '/\+$/ {printf "%s", substr($0, 0, length($0)-1); next}; 1' file

For lines that end with a plus, print the line (minus the plus) without a newline.
For other lines, print with a newline.

Upvotes: 1

Related Questions