linux tr命令实现windows文本格式与linux文本格式间的转换

tr 命令
转换和删除字符

选项:
-d --delete:删除字符
-s --squeeze-repeats:把连续重复的字符以一个字符表示,即去重

该命令会把/etc/issue中的小写字符都转换成大写字符
tr ‘a-z’ ‘A-Z’< /etc/issue
删除fstab文件中的所有abc中任意字符
tr –d abc < /etc/fstab

windows文本格式与linux文本格式间的转换,windows格式文本中比linux格式文本中多回车键’\r’,通过tr删除’\r’实现格式转换
实例如下:
[root@localhost ~]# cat windows.txt
a
b
c

[root@localhost ~]# file windows.txt
windows.txt: ASCII text, with CRLF line terminators
[root@localhost ~]# hexdump windows.txt 
0000000 0d61 620a 0a0d 0063                    
0000007

[root@localhost ~]# tr -d '\r' <windows.txt >linux.txt

[root@localhost ~]# file linux.txt
linux.txt: ASCII text
[root@localhost ~]# hexdump linux.txt 
0000000 0a61 0a62 0063                         
0000005

[root@localhost ~]# cat linux.txt
a
b
c

注意:不能使用 tr 命令将文件从 Unix 格式转换为 Windows(DOS)。

除此之外Linux还提供了两种文本格式相互转化的命令:dos2unix和unix2dos,dos2unix把"\r\n"转化成"\n",unix2dos把"\n"转化成"\r\n"。

相关文章

Windows2012R2备用域控搭建 前置操作 域控主域控的主dns:自...
主域控角色迁移和夺取(转载) 转载自:http://yupeizhi.blo...
Windows2012R2 NTP时间同步 Windows2012R2里没有了internet时...
Windows注册表操作基础代码 Windows下对注册表进行操作使用的...
黑客常用WinAPI函数整理之前的博客写了很多关于Windows编程的...
一个简单的Windows Socket可复用框架说起网络编程,无非是建...