标签:windows tr 文本格式 linux txt root localhost
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"。
标签:windows,tr,文本格式,linux,txt,root,localhost 来源: https://www.cnblogs.com/xiaodiky/p/15418350.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。