Remove carriage return in a record

Hi all gurus,

I need help in removing carriage return existed within a record delimited by pipe <|>.

Sample:
A_01|Test1|Testing1|Remarks1
A_02|Test2|Test
ing2|Remarks2
A_03|Test3|Testing3|
Remarks3

Desire output:
A_01|Test1|Testing1|Remarks1
A_02|Test2|Testing2|Remarks2
A_03|Test3|Testing3|Remarks3

I came across the thread in removing carriage return as below,

but it is looking for keywords ADD,MODIFY,DELETE

Need your help on this matter. Thanks alot.

awk -F'|' 'NF != 4 || !$4 {printf $0; getline} 1' INPUTFILE  

Thanks Yazu for your quick response.

However, it seems not working.

In addition, from the awk command issued, is the command limited number of column as 4? The source files to be processed may have different number of columns.

It works for your example (GNU awk with either --posix or --traditional options). And yes it's only for 4 fields. Give more real example.

when executing the command, it hits this 2 lines

awk: syntax error near line 1
awk: bailing out near line 1

what i need to configure in order to execute awk?

which is your OS? if solaris use /usr/xpg4/bin/awk

regards,
Ahamed

Or "nawk".

Thanks all for your response, it works with 'nawk'.

However, if there is no fix number of columns in a source file, how should i tackle the situation? The example here i provided 4 columns, in actual fact the source file has more. And there are total of 4 types of source file i need to clean up the carriage return.

Example:
file 1 has 15 columns in the source file
file 2 has 27 columns in the source file
file 3 has 26 columns in the source file
file 4 has 29 columns in the source file

Is there a way to not hardcode the number of columns in nawk command?

Thanks for your advice.

Modify the code accordingly for the 4 different files

file 1 with 15 columns

awk -F'|' 'NF != 15 || !$15 {printf $0; getline} 1' inputfile

regards,
Ahamed

You need something to define whether the line is full of not. There are may be other ways to get this from your file (the first line maybe) but it's impossible to see your files at a distance. Or you could learn the number as the max number of fields from exploring the file before processing.
.

Yazu, thanks.

In that case, how do i count the max number of column in the source file? Indeed, the source file comes with column header.