Removal of carriage returns from a comma delimited file

Hi,

I have a file which is having some carriage return in one of the field for which single line is coming in multiple lines.

I want to combine all those multiple lines of that field into one line.

Eg:

Input:

 
Id, Name, Location, Comments, Dept
2, John, US, I am from US.
I live in NC.
I am working on Unix, Finance
3, Jack, UK, I am from UK.
I live in London, Accounts

Desired Output:

Id, Name, Location, Comments, Dept
2, John, US, I am from US.I live in NC.I am working on Unix, Finance
3, Jack, UK, I am from UK.I live in London, Accounts

Any solution for this would be of really helpful.. Thanks.

Mahesh

Please post sample output from:

sed -n l filename

This is designned to make normal unix line terminators visible and carriage-returns visible. We need to know that they are actually carriage-return characters.

Here is the out of the command "sed -n l"

 
Id, Name, Location, Comments, Dept$
2, John, US, I am from US.$
I live in NC.$
I am working on Unix, Finance$
3, Jack, UK, I am from UK.$
I live in London, Accounts$
 

Is it always the comment section that is broken over multiple lines?

Yes its always the comments field that comes in multiple lines

Try:

awk 'END{print x}/^[0-9]*,/,/^[^0-9]/{printf "%s", $0;next}1' infile
1 Like