Question: I have dos file by default populating with CRLF as line breakers. But , some times I get LF instead of CRLF. I need to figure where exactly change is occurring for line breaks.And I don't want to replace LF with CRLF.Just to look at the change of record with line breaker

Answer: 
Given the following short example:

```
$ cat -et file
122323432.....^M$
4354363645....^M$
45234564655...$
34r52435346...^M$
122323432.....^M$

```

(where `cat -et` is used to display the line endings) then

```
$ awk '{last = $0} NR==1 {cr = /^M$/ ? 0 : 1; next} cr == 0 && /^M$/ {print last; cr = 1} cr == 1 && !/^M$/ {print last; cr = 0}' file | cat -et
4354363645....^M$
45234564655...$
34r52435346...^M$

```

where the `^M` are entered as actual CR characters using `Ctrl`+`V` `Enter` for example.

---

Here's a somewhat literal attempt at a `python` translation:

```
#!/usr/bin/python3

import re

p = re.compile(r'.*\r$')

with open('file', 'r', newline='') as f:
    for idx, line in enumerate(f):
        last = line
        m = p.match(line)
        if (idx==0):
            cr = 0 if m else 1
        if (cr==0) and m:
            print(last, end='')
            cr = 1
        elif (cr==1) and not m:
            print(last, end='')
            cr = 0

```
With GNU grep:

```
grep --binary -v $'\r'$ dosfile

```

Sample input (with a joker on line 3 holding a caret and an M):

```
$ cat -e dosfile
line1^M$
line2^M$
line3 joker ^M^M$
line4^M$
line5^M$
line6$
line7$

$ od -c dosfile
0000000   l   i   n   e   1  \r  \n   l   i   n   e   2  \r  \n   l   i
0000020   n   e   3       j   o   k   e   r       ^   M  \r  \n   l   i
0000040   n   e   4  \r  \n   l   i   n   e   5  \r  \n   l   i   n   e
0000060   6  \n   l   i   n   e   7  \n
0000070

$ grep --binary -v $'\r'$ dosfile
line6
line7

```