Removing CRLF combo but not CR or LF when alone

What is the command or script to remove CRLF but only when joined?

Tried using below but removed all instances of either
cat a.txt | tr -d "\r\n" > b.txt

perl -pe 's/\r\n//' a.txt > b.txt

This didn't work. The new file was created but:

Instances of LF were changed to CRLF and original instances of CRLF were ignored.

What you are saying is not possible with the command I suggested.
Please, post some of the original data.

I've attached a sample. You'll see LF at the end of an appropriate line break, and CRLF within fields I want to remove.

thanks for the insights.

strange, the only things I see "within fields" are ^I-s (in vi) which are TABs...

Try:

awk '{sub(/^\n/,x)}1' RS='\r' ORS='\r' file

the awk command produced the same issue..... bad CRLF remains and correct LF at line endings changed to CRLF.

what is needed is to remove the CRLF in mid-row, and the correct line endings remain (LF or CRLF, doesn't matter)

I'll add screen shots from notepad++

screenshots attached

Hum.... Let me see if I understand.... You want to remove CRLF if the next field/line start with a tab? Which will result in joining the lines?
Coule you also take a small sample of adjoining lines and upload the original and the desired files?

Wouldn't it be easier to correct the (line breaks in the) cells in your spread sheet program (CALC, EXCEL, etc ...) than having people in here puzzling over this undecipherable file? Shooting in the dark, try

awk '{while (sub (/\r$/,_)) {getline T; $0 = $0 T}} 1'  /tmp/mozilla/testdata.txt

needs to be automated as its becoming a daily import to our db.

Simply put, I want to leave the LF marks untouched.... and remove all CRLF when CRLF are found together

thanks all

The command:

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

will remove all <carriage-return><newline> character pairs from a file named file . It produces exactly the same output as the code RudiC suggested in post #11, but uses a slightly different approach to get there. If you want to try either of these on a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk or nawk .

The screenshots you provided in post #9 do not provide any useful information to us. (At least not to me.)

Note that the file you uploaded in the file testdata.txt in post #5 contains lots of <carriage-return><newline> character pairs, but it does not contain any <carriage-return> characters that are not immediately followed by a <newline> character.

If you want to keep the <CR> in the lines, this might do:

awk '/\r$/ {ORS=""} 1; {ORS=RS}'  /tmp/testdata.txt

Thank you.
Before:

DEBT_COMM=Client was initially responsive, however has become unresponsive for t
he past 2-3 weeks. The final instalment amount noted is now almost 2 months over
due.^M                                                                          
^M                                                                              
Our agreements stipulate a 20% interest fee on top of the overdue amount, to cov
er collections fees.^M                                                          
^M                                                                              
We have worked with you before and would like to obtain a quote for collection s

After:

DEBT_COMM=Client was initially responsive, however has become unresponsive for t
he past 2-3 weeks. The final instalment amount noted is now almost 2 months over
due.Our agreements stipulate a 20% interest fee on top of the overdue amount, to
 cover collections fees.We have worked with you before and would like to obtain 
a quote for collection service of this debtor. You can download the associated i

We have a web form that has an embedded javascript that prevents the <enter> key from submitting the form. The downside of which is that carriage returns can appear in comment boxes.