处理文件CRLF line terminators的问题
2014-04-03 00:00
106 查看
摘要: 处理文件CRLF line terminators的问题
对比file1.log和file2.log中相同重复的行。
发现很容易实现,直接:
$ for i in `cat file1.log`; do grep $i ./file2.log; done > sameline.log
结果就发现只有一条,研发的同学说至少有上万条记录,我开始找原因:
先输出测试看看格式什么的对不对:
$ for i in `cat file1.log`; do echo "AAA"$i"BBB"; done
BBBxxxxxxxxxxx05_ok
BBBxxxxxxxxxxx06_ok
BBBxxxxxxxxxxx07_ok
BBBxxxxxxxxxxx08_ok
调试一下,发现输出的两端的字符,会选择长度较大的放在最左侧(可以自己试试哈),我一直觉得和换行符有关系,实际上是文件格式的问题。
我最终file了一下源文件和自己再终端随便写的test.log
$ file file1.log
file1.log: ASCII text, with CRLF line terminators
$ file test.log
test.log: ASCII text
终于发现端倪,原来是之前的研发给的结果是win下处理的,是windows的某种格式,没有细究,有兴趣的同学自己去研究文件的格式吧。
总之解决问题最重要:
$ dos2unix file1.log file2.log
file1.logdos2unix: converting file tile1.log to UNIX format ...
file2.logdos2unix: converting file tile2.log to UNIX format ...
测试一下:
$ for i in `cat file1.log`; do echo "AAA"$i"BBB"; done
AAAxxxxxxxxxxx05_okBBB
AAAxxxxxxxxxxx06_okBBB
AAAxxxxxxxxxxx07_okBBB
AAAxxxxxxxxxxx08_okBBB
OK,问题解决。
对比file1.log和file2.log中相同重复的行。
发现很容易实现,直接:
$ for i in `cat file1.log`; do grep $i ./file2.log; done > sameline.log
结果就发现只有一条,研发的同学说至少有上万条记录,我开始找原因:
先输出测试看看格式什么的对不对:
$ for i in `cat file1.log`; do echo "AAA"$i"BBB"; done
BBBxxxxxxxxxxx05_ok
BBBxxxxxxxxxxx06_ok
BBBxxxxxxxxxxx07_ok
BBBxxxxxxxxxxx08_ok
调试一下,发现输出的两端的字符,会选择长度较大的放在最左侧(可以自己试试哈),我一直觉得和换行符有关系,实际上是文件格式的问题。
我最终file了一下源文件和自己再终端随便写的test.log
$ file file1.log
file1.log: ASCII text, with CRLF line terminators
$ file test.log
test.log: ASCII text
终于发现端倪,原来是之前的研发给的结果是win下处理的,是windows的某种格式,没有细究,有兴趣的同学自己去研究文件的格式吧。
总之解决问题最重要:
$ dos2unix file1.log file2.log
file1.logdos2unix: converting file tile1.log to UNIX format ...
file2.logdos2unix: converting file tile2.log to UNIX format ...
测试一下:
$ for i in `cat file1.log`; do echo "AAA"$i"BBB"; done
AAAxxxxxxxxxxx05_okBBB
AAAxxxxxxxxxxx06_okBBB
AAAxxxxxxxxxxx07_okBBB
AAAxxxxxxxxxxx08_okBBB
OK,问题解决。
相关文章推荐
- [转]处理文件CRLF line terminators的问题
- CRLF line terminators导致shell脚本报错:command not found --转载
- sublime with CRLF line terminators
- CRLF line terminators导致shell脚本报错:command not found
- Little-endian UTF-16 Unicode text, with very long lines, with CRLF line terminators
- 解决EditorLineEnds.ttr被锁定导致Delphi2006-2010无法启动的问题
- Inline hook ObReferenceObjectByHandle,附加问题笔记做记录
- display:inline-block元素间距问题
- Java中Scanner类在nextInt()后无法输入nextLine()的问题
- jquery Multiple markers at this line问题
- mysql5.5安装成功后无法使用MySQL 5.5 Command Line Client的问题
- MySQL中MySQL X.X Command Line Client一闪而过的问题
- line-height属性遇到的问题
- python问题Non-ASCII character '\xe5' in file Apriori.py on line 1, but no encoding declared 解决办法
- 关于echarts的markline线上的数值的上下移动问题
- 如何解决dubbo配置文件中Multiple annotations found at this line问题
- ILJMALL project过程中遇到Fragment嵌套问题:IllegalArgumentException: Binary XML file line #23: Duplicate id
- phoenix psqlline输入命令无法删除问题解决技巧
- 去除display:inline-block下的元素间隔问题
- 关于宏的一些问题,和__LINE__,__FILE__一些编辑器默认宏