Removing carriage returns from multiple lines in multiple files of different number of columns

Hello Gurus,

I have a multiple pipe separated files which have records going over multiple Lines. End of line separator is \n and records going over multiple lines have <CR> as separator. below is example from one file.

1|ABC DEF|100|10
2|PQ
RS
T|200|20
3| UVWXYZ|300|30
4| GHIJKL|400|40

I am after the output as below

1|ABCDEF|100|10
2|PQRST|200|20
3|UVWXYZ|300|30
4|GHIJKL|400|40

I have tried various options mentioned in the forum but it doesn't seems to be working on records with on multiple lines on mutiple files in a directory

Any help would be appreciated.

Thans

DEV

Please, try:

perl -0pe 's/(?:\n|\s+)(\D)/$1/g' example.txt

or

perl -0pe 's/[\n\s]+(\D)/$1/g' example.txt

Output:

1|ABCDEF|100|10
2|PQRST|200|20
3|UVWXYZ|300|30
4|GHIJKL|400|40

There do not seem to be <CR> characters present in the input file only newlines (\n) ?

Wouldn't a mere tr -d $'\r' <file help?

Hi
Aia :- How do use the Perl commands on Solaris. do you need to include something in the shell script for the Perl commands to work.

Scrutinizer :-There are <CR> in the file. Its just that I havent added it.

Thanks

Could you provide a sample file that Contains CR's ?

Hi Scrutinizer,

Thanks for your response but honestly even I don't have access to sample files as files are in test environment. If I have to test the commands provided by you all gurus, I will have to run the commands on our test environment.

Without proper sample/test data, this is shooting in the dark. Don't expect any solid, tested, dependable solution for your problem if you promise "There are <CR> in the file" but you ". . . just . . . havent added it."