UNIX/Linux Commands

You can use the following tools:

  • dos2unix (also known as fromdos) – converts text files from the DOS format to the Unix
    format
  • unix2dos (also known as todos) – converts text files from the Unix format to the DOS format.
  • sed – You can use sed command for same purpose
  • tr command
  • Perl one liner

Task: Convert DOS file to UNIX format

Type the following command to convert file called myfile.txt:
$ dos2unix myfile.txt

However above command will not make a backup of original file myfile.txt. To make a backup of original file. The original file is renamed with the original filename and a .bak extension. Type the following command:
$ dos2unix -b myfile.txt

Task: Convert UNIX file to DOS format

Type the following command to convert file called myfile.txt:
$ unix2dos myfile.txt
$ unix2dos -b myfile.txt

Task: Convert Dos TO Unix Using tr Command

Type the following command:

tr -d '\r' < input.file > output.file

Task: Convert Dos TO Unix Using Perl One Liner

Type the following command:

perl -pi -e 's/\r\n/\n/g' input.file

Task: Convert UNIX to DOS format using sed command

Type the following command if you are using bash shell:
$ sed 's/$'"/`echo \\\r`/" input.txt > output.txt
Note: sed version may not work under different UNIX/Linux variant,refer your local sed man page for more info.

Task: Convert DOS newlines (CR/LF) to Unix format using sed command

If you are using BASH shell type the following command (press Ctrl-V then Ctrl-M to get pattern or special symbol)
$ sed 's/^M$//' input.txt > output.txt
Note: sed version may not work under different UNIX/Linux variant, refer your local sed man page for more info.

shell crlf to lf的更多相关文章

  1. 趣谈、浅析CRLF和LF

    作为程序员,在处理文件和输入输出的时候经常要跟CRLF和LF打交道.可能大家多少知道一些,但总是记不清楚,我也是这样的,因此写下这篇博文,作为记录. 首先,明确他们的意思:CR(回车),LF(换行). ...

  2. eslint 关于CRLF或者LF报错

    在拉取项目代码时,如果有eslint代码校验,但是本地打开会有于CRLF或者LF报错报错,那么怎么处理呢? git有个自动转换换行符功能,在文件commit时会自动转换换行符格式: 不想使用,也可以通 ...

  3. Git 换行符检查 CRLF 与 LF

    遇到的问题 在 git 提交或是签出时,提示如下问题: [git] warning: LF will be replaced by CRLF | fatal: CRLF would be replac ...

  4. [git] warning: LF will be replaced by CRLF | fatal: CRLF would be replaced by LF[ git 处理和修改行结束符(CRLF和LF)]

    我自己的设置是: [core] autocrlf = false[core] safecrlf = true 取消自动转换CRLF(上图中选的是commit as is),但是有提交前混用检查 本人用 ...

  5. 解决crlf 和 lf不同带来的冲突问题

    crlf 和 lf 是文本换行的不同方式: crlf: "\r\n", windows系统的换行方式 lf: "\n", Linux系统的换行方式 他们之间的不 ...

  6. CRLF和LF

    协作项目,开发环境不同(mac,window)构建过程中,命令行报错(expecting LF but only find CRLF) 打开git bash,输入 $ git config --glo ...

  7. Git操作中crlf和lf冲突问题

    多人参与项目开发的时候,经常会遇到代码格式化不一致,在提交的时候出现很多冲突的情况.其中换行符冲突就是一种,在不同的系统平台上是不一样的.UNIX/Linux 使用的是 0x0A(LF),早期的 Ma ...

  8. CRLF与LF解析

    window和mac的同学合作开发项目,会出现git提交/拉取时换行符不一致导致,提示 "the text is identical, but the files do not match, ...

  9. Notepad++ 替换 CRLF 为 LF

    对于文件中每一行的结尾符号,Windows 下默认为 CRLF,而 Unix 下默认为 LF. 所以经常会有这样的情况发生:在 Windows 系统下编辑的文件放在 Unix 下不能正常执行,比如 b ...

随机推荐

  1. 对Swoole、Workerman和php自带的socket的理解

    为什么php自带的socket不怎么听说,基本都是用swoole,workerman去实现? 1.PHP的socket扩展是一套socket api,仅此而已. swoole,用C实现,它的socke ...

  2. hishlib 算法加密

    通过hashlib MD5得到一个32的加密密码 import hashlib def getMD5(): md5 = hashlib.md5()  #调用MD5加密方法 with open(path ...

  3. ERROR 2002 (HY000): Can't connect to local MySQL server through socket '***' (2)

    有时候,当我们使用“mysql”.“mysqladmin”.“mysqldump”等命令管理数据库时,服务器抛出类似如下错误: ERROR (HY000): Can't connect to loca ...

  4. Gson将字符串转map时,int默认为double类型

      gson能够将json字符串转换成map, 但是在转成map时, 会默认将字符串中的int , long型的数字, 转换成double类型 , 数字会多一个小数点 , 如 1 会转成 1.0 Gs ...

  5. linux:安装并使用mongo

    1.下载mongo:  curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.0.6.tgz 2.解压: tar -zxvf ...

  6. Just Oj 2017C语言程序设计竞赛高级组D: 字符串最大表示(next数组)

    D: 字符串最大表示 时间限制: 1 s      内存限制: 128 MB 题目描述 有如下定义,abcnabcn表示字符串abc重复n次,例如abc2abc2表示abcabc. 给定一个字符串,求 ...

  7. Pycharm常用操作方法

    1.调整字体大小 2.选择python编译器

  8. Leetcode刷题第003天

    一.只出现一次的数字 class Solution { public: int singleNumber(vector<int>& nums) { ; for (auto num ...

  9. webpack学习笔记--其它配置项

     其它配置项 除了前面介绍到的配置项外,Webpack 还提供了一些零散的配置项.下面来介绍它们中常用的部分. Target JavaScript 的应用场景越来越多,从浏览器到 Node.js,这些 ...

  10. OpenJDK-study-001 windows上安装Mercurial 4.4.1 克隆OPENJDK版本库

     下载安装 1.下载Mercurial 进入https://www.mercurial-scm.org/wiki/Mercurial下载,windows上傻瓜式安装的,安装好之后,命令行进入安装目录, ...