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

```
If your system has `cat` with the `-e` switch, you can use it to see the carriage returns. Here, the first line has a CR (shown as `^M`), the second one doesn't.

```
$ cat -e crlf
foo^M$
bar$

```

(Though if some joker wrote a literal caret + `M` combination in your file, it'll look just the same as a CR.)

Alternatively, use `less -U` (provided `-r` is not given), it shows carriage returns similarly as `^M`, but in reverse color.