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

车东[Blog^2] 2019-07-26 14:08:20 累计浏览 1,821 次

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.


同分类推荐文章

  1. NGINX Gateway Fabric 2.8: IP allow and deny lists, passive health checks, and cookie-based session persistence (2026-11-14 01:10:02)
  2. NGINX Ingress Controller 5.7: HTTP/2 to your upstreams, Opaque Secrets, and cert-manager challenges behind HTTPS redirects (2026-11-14 00:10:02)
  3. Hexo 文章一键发布到微信公众号 (2026-11-13 19:10:02)

查看更多 DevOps 文章 →

建议继续学习

  1. Git常用命令备忘 (累计阅读 55,165)
  2. 简明Vim练级攻略 (累计阅读 22,917)
  3. 28个Unix/Linux的命令行神器 (累计阅读 17,183)
  4. find命令的一点注意事项 (累计阅读 12,367)
  5. 100个常用的linux命令 (累计阅读 11,999)
  6. 每个程序员都应该知道的8个Linux命令 (累计阅读 11,030)
  7. perl更新/修改/删除文本文件内容 (累计阅读 10,899)
  8. colortail,让 tail 命令绚丽起来 (累计阅读 10,797)
  9. 最受欢迎的10个 Linux 单行命令 (累计阅读 10,435)
  10. AWK 简明教程 (累计阅读 9,676)