笔记 by 车东

Mac下处理PC以^M结尾的文本

· 日志分析|Analytics

📌 TLDR

用 awk 处理 PC 的 CRLF 文本:awk -v RS='\r\n' 直接把 \r\n 当记录分隔符;顺带复习三种行末约定 —— Unix \n、老 Mac \r、Windows \r\n。

awk -v RS=’\r\n’ foo.log

Unix 用\n行末结尾 Mac 用\r行末结尾 PC 用 \r\n行末结尾

参考: https://stackoverflow.com/questions/13069905/awk-print-is-adding-a-control-m-character-at-end-of-line#comment17754368_13069905 The record separator is automatically set to the line-ending of the current system, LF (\n) on the Unix-based systems, CR-LF (\r\n) on MS systems and CR (\r) on Mac OS prior to Mac OS X.