sed 替换换行回车
A carriage return linefeed (CRLF) is a special sequence of characters, used by DOS/Windows, to signify the end of a line of text. However, in *nix, only a linefeed (LF) is required to signify a line ending.
test.CRLF.txt
12345CRLF
12345LF
Delete/Replace a Carriage Return (CR) with sed
There are a few ways to remove or replace a carriage return with sed.
sed 's/.$//' test.CRLF.txt > test1.txt
12345LF
1234LF
sed 's/\x0D$//' test.CRLF.txt > test2.txt
12345LF
12345LF
sed 's/\r//' test.CRLF.txt > test3.txt
12345LF
12345LF
The first method assumes all lines end with CRLF, while the second and third method depend on the version of sed.
Delete/Replace a Linefeed (LF) with sed
By default, sed strips the newline as the line is placed into the pattern space. However, the workaround is to read the whole file into a loop first.
sed ':a;N;$!ba;s/\n/<text>/g'
where
:a - create a label 'a'
N - append the next line to the pattern space
$! - if not the last line
ba - branch (go to) label 'a'
s - substitute
/\n/ - regex for new line
/<text>/ - with text "<text>"
g - global match (as many times as it can)
Example: Delete Newlines (CRLF) with sed
Delete the carriage return first, and then delete the linefeed.
sed -i 's/\r//g' example.txt
sed example delete newline carriage return.png
sed -i ':a;N;$!ba;s/\n/<text>/g' example.txt
sed example delete newline linefeed.png
tr: A Simpler Way to Replace or Delete a Newline (CRLF)
The tr utility is a preferred and simpler method for replacing end of line characters as the pattern buffer is not limited like in sed.
tr '\r\n' '<replace with text>' < input_file > output_file
or to delete the newline (CRLF),
tr -d '\r\n' < input_file > output_file
where
\r - carriage return
\n - linefeed
Example: Delete Newlines (CRLF) with tr
tr -d '\r\n' < example.txt > example2.txt
tr example delete newline CRLF.png
Command Line Examples
Note: The command cat will concatenate files and print on the standard output. The option A will use ^ and M notation to show non-printing characters, display $ at end of each line, and display TAB characters as ^I.
REF:
http://www.canbike.org/information-technology/sed-delete-carriage-returns-and-linefeeds-crlf.html
ABHD12
ABI2
ACSM2A
ACSM2B
AGPAT5
ANP32B
APP
ARID1A
ARL10
BACH2
FBXL2
FBXO22
FBXO30
FBXO39
sed 替换换行回车的更多相关文章
- sed替换换行符“\n”
linux sed命令,如何替换换行符“\n” 在一次sed使用中,执行命令: sed "s/\n//g" file 1 发现,没起到任何效果. 后来,经查sed官方用户手册,才得 ...
- sqlserver查询的结果复制到excel替换掉回车换行
从sqlserver查询统计出的结果复制到excel,如果有回车,换行 ,或回车换行 ,复制到excel显示会乱会错版,查询的时候就替换掉回车换行,复制出来就不会乱了 ) ), ),),'') fro ...
- JS替换空格回车换行符
JS替换空格回车换行符 str=str.replace(/\r/g," ") str=str.replace(/\n/g,"<br />") 或 ...
- 替换换行符:回车换行CR/LF
windows采用回车+换行CR/LF表示下一行,UNIX/Linux使用换行符LF表示下一行,MAC OS系统使用用回车符CR表示下一行. CR使用符号'\r'表示, ASCII码是13: LF使用 ...
- php去除换行(回车换行)的方法
php去除换行(回车换行)的三种方法. 代码: <?php //php 不同系统的换行 //不同系统之间换行的实现是不一样的 //linux 与unix中用 \n //MAC ...
- sed 删除换行符
sed 删除换行符 sed ':label;N;s/\n/:/;b label' filename sed ':label;N;s/\n/:/;t label' filename 上面的两条命令可以实 ...
- Python3学习之路~2.8 文件操作实现简单的shell sed替换功能
程序:实现简单的shell sed替换功能 #实现简单的shell sed替换功能,保存为file_sed.py #打开命令行输入python file_sed.py 我 Alex,回车后会把文件中的 ...
- mysql去除字段内容的空格和换行回车
MySQL 去除字段中的换行和回车符 解决方法: UPDATE tablename SET field = REPLACE(REPLACE(field, CHAR(10), ''), ...
- Python3.5 day3作业一:实现简单的shell sed替换功能
需求: 1.使python具有shell中sed替换功能. #!/usr/bin/env python #_*_conding:utf-8_*_ #sys模块用于传递参数,os模块用于与系统交互. i ...
随机推荐
- HighCharts学习笔记(一)
HighChars基本概述 Highcharts是一个纯js写成的插件库,很好的外观表现可以满足任何图标需求. 开始使用chart之前进行配置 全局配置: Highcharts.setOptions( ...
- hdu5067
题意 给了一个n*m的网格 然后一台挖掘机从(0,0) 这个位置出发,收集完全部的石头回到(0,0)挖掘机可以有无限的载重 用旅行商处理 dp[k][i] 表示在这个集合中最后到达i的最小距离,用集合 ...
- Sitecore CMS中更改项目的模板
如何在Sitecore CMS中创建项目后更改项目的模板. 在创建项目时选择了错误的模板,或者创建了新模板并将现有项目更新为新模板时,这非常有用. 警告! 更改模板时要小心.如果原始模板具有不在新 ...
- 如何在Sitecore CMS中创建项目
从功能区 打开Sitecore的内容编辑器,选择内容树中的项目.创建的项目将作为所选项目的子项添加. Sitecore 8显示所选的Home项目 Sitecore 6和7显示所选的Home项目 功能区 ...
- 使用Java注解自动化处理对应关系实现注释代码化
概述 假设我们要从一个 ES 索引(相当于一张DB表)查询数据,ES表有 biz_no, type, status 等字段, 而应用对象则有属性 bizNo, type, status 等.这样,就会 ...
- 配置开发环境2——eclipse配置
纯手动配置eclipse, Eclipse配置 配置工作空间的编码方式 General—Workspace:改成Other:UTF-8 配置property的编码方式 配置maven Window — ...
- c# 对话框控件
对话框也是一种窗体,通常调用对对话框相关类型的ShowDialog方法来弹出对话框,当用户关闭对话框后,该方法会返回一个DialogResult枚举值,通过该值就可以判断用户采取了什么操作,例如单击确 ...
- CentOS7 zabbix服务 简单安装文档
1. 简介 zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案. zabbix能监视各种网络参数,保证服务器系统的安全运营:并提供灵活的通知机制以让系统管理员快 ...
- WTL CHyperLink类的使用(超链接)
1.包含atlctrlx.h头文件: 2.声明一个CHyperLink类的变量: CHyperLink m_linkIntro; 3.在OnInitDialog函数里: m_linkIn ...
- dropout——gluon
https://blog.csdn.net/lizzy05/article/details/80162060 from mxnet import nd def dropout(X, drop_prob ...