Adding CR to ascii data file generated on AIX platform and will be transmitted to Windows OS

I desperately need help converting ascii data file generated on AIX platform that contains dollar sign ($) at the end of each line in the data file as shown below.

ME570^0128237^HG278999^20140805:21:00:00^BEENZ001^$

This is the AWK command for adding CR to the new line.

awk '{sub("$","\r\n"); printf("%s",$0);}' inputfile > outputfile

When I execute this AWK command to add Carriage Return before the new line it works fine from the command line like shown below.

ME570^0128237^HG278999^20140805:21:00:00^BEENZ001^M$

but it add double CRs like CRCRLF in the ascii data file when is executed as korn shell script as shown below.

ME570^0128237^HG278999^20140805:21:00:00^BEENZ001^M^M$

Do you have a suggestion on how to resolve this issue. Any help is appreciated.

Thanks
Nnamdi

The script you used:

awk '{sub("$","\r\n"); printf("%s",$0);}' inputfile > outputfile

would produce double spaced lines (with a carriage return at the end of the 1st line of every pair. To get what you wanted, you could try:

awk '{sub("$","\r"); printf("%s",$0);}' inputfile > outputfile

or more simply:

awk '{print $0 "\r"}' inputfile > outputfile

Also see if your system provides a unix2dos utility.

1 Like