How to Remove the new line character inbetween a record

I have a file, in which a single record spans across multiple lines,

File 1
====
14|\n 
leave request \n
accepted|Yes|
15|\n 
leave request not \n
acccepted|No|
 

I wanted to remove the '\n charecters. I used the below code (foudn somewhere in this forum)

perl -e 'while (<>) { if (! /\|$/ ) { chomp; } print ;}' input.dat > output.dat
 

The above code returns the ouptut as
line 1: 14|\n
line 2: leave request accepted|Yes| (end of record)

line3: 15|\n
line 4: leave request not acccepted|No| (end of record)

still the new line characters at the begining of the field still remains and a single record is split as two records.

My expected output is
line 1: 14|leave request accepted|Yes| (end of record)

line3: 15|leave request not acccepted|No| (end of record)

Can some one please help me in this issue?:frowning:

Hi machomaddy,

That 'perl' code seems to work for me, here you have other one (perl too). It supposes that each three input lines there should be an output line:

$ cat infile
14| 
leave request 
accepted|Yes|
15| 
leave request not 
acccepted|No|
$ perl -ne 's/(?<=\|)\s*$/\n/; if ( $. % 3 ) { chomp } print' infile
14|leave request accepted|Yes|
15|leave request not acccepted|No|

Regards,
Birei