Losing carriage return (X0D) after running awk command

Hi Forum.

I'm running the following awk command to extract the suffix value (pos 38) from the "AM00" record and append to the end of the "AM01" record.

awk 'substr($0,13,4)=="AM00" {SUFFIX = substr($0,38,2)} substr($0,13,4)=="AM01" {$0 = $0 SUFFIX} 1'  before.txt > after.txt
Before.txt:
000000000001AM00 1500895700000000000187                                  
000000000001AM01 035000000000013000399820810000000

AM01 record - In hex value:
.....20 20 20 20 20 20 0D 0A

After.txt:
000000000001AM00 1500895700000000000187                                  
000000000001AM01 03500000000001300039982081000000087

AM01 record - In hex value:
.....20 20 20 20 20 20 38 37 0A

It seems or appears that the Hexadecimal 0D was removed after running the awk command.

Any way to resolve this?

Thanks.

Are you sure the hex dump is from the same file? It should read . . . 30 30 38 37 0A , then.
awk wouldn't remove the 0x0D but leave it where it was - just before the 87 , and thus the 87 should be printed at BOL (begin of line).

What OS/shell/ awk versions do you use?

GNU Awk 4.1.1, API: 1.1 (GNU MPFR 3.1.2, GNU MP 6.0.0)
Copyright (C) 1989, 1991-2014 Free Software Foundation.

CYGWIN_NT-6.3 STCTQAINFAPP52 1.8.6-2(0.280/5/3) 2014-11-07 09:47 x86_64 Cygwin - I'm actually running Cygwin (Unix emulation) on Windows.

I have attached a picture of the data before/after running the awk command.

Thank you.