Appending CRLF to end of record

I need to append |\r\n (a pipe character and CRLF) at end of each record in Unix to all records where they are not already present.

So first check for the presence of |\r\n and if absent append it else do nothing

Hello Abhilash,

Could you please provide some test input for same.

Thanks,
R. Singh

awk '{$0=$0 ~ /\|\r\n$/?$0:$0"|\r\n"} 1' filename>output

worked for me

This request, or highly similar ones, have been covered in these forums umpteen times. Did you consider a search upfront?

Depending on your system version, this may do:

sed '/|\r$/!s/$/|\r/' file

Please be aware that it looks for the combination you specified; should there be e.g. a single "|" at line end, a "|"\r combination will be added.