Suppress/remove carriage return from awk output

You should remove the -t option from ssh in order to prevent generating the carriage return in the first place.

The -t option directs ssh to allocate a pseudo terminal on the remote machine, and if that terminal has the onlcr flag set (which is the default), every LF (\n) will be translated to CR/LF (\r\n) on output. The -t option is not needed unless a full-screen and/or interactive program is run, like vi or screen.

But if you really have to process lines terminated by CR/LF in awk, you can set the record separator to CR/LF in any awk implementation which supports multi-character/regex record separators -- like gawk or mawk. Example:

awk ... 'BEGIN{RS="\r\n"}{...}'

Also, if you want to remove a stray CR from a field in awk, you can use sub or gsub (which works everywhere):

gsub("\r","",$6)

Tags:

Awk