文本文档,excel-txt-bed-terminal,换行符的问题
如果txt file 或者 bed file 是excel 导出的时候,当运用 cat 行结合两个文本文档的时候会出现换行问题
http://sphenginx.github.io/2014/12/24/CRLF-in-Unix-like_Windows-os/
第一个只适用一般的txt,而不是bed file
在windows下将txt文件保存为ANSI格式,然后在Linux终端输入:
cat ms.txt | col -b > linux.txt
mac 里的excel保存txt, 要保存为windows formatted test (.txt)
bash-3.2$ cat file1.txt
1
2
3
4
5bash-3.2$ cat file2.txt
1
2
3
4
5
6
7
8
9
10bash-3.2$ cat -v file1.txt
1^M
2^M
3^M
4^M
5bash-3.2$ wc file1
wc: file1: open: No such file or directory
bash-3.2$ wc file1.txt
4 5 13 file1.txt
bash-3.2$ wc -l file1.txt
4 file1.txt
bash-3.2$ cat file1.txt file2.txt > file3.txt
bash-3.2$ cat file3.txt
1
2
3
4
51
2
3
4
5
6
7
8
9
10bash-3.2$ cat vi file1.txt
cat: vi: No such file or directory
1
2
3
4
5bash-3.2$ vi file1.txt
bash-3.2$ cat file1.txt | col -b > file1_1.txt
bash-3.2$ cat -v file1_1.txt
1
2
3
4
5
bash-3.2$ cat -v file1.txt
1^M
2^M
3^M
4^M
5bash-3.2$ cat file2.txt | col -b > file2_1.txt
bash-3.2$ cat -v file2.txt
1^M
2^M
3^M
4^M
5^M
6^M
7^M
8^M
9^M
10bash-3.2$ cat -v file2_1.txt
1
2
3
4
5
6
7
8
9
10
bash-3.2$ cat file1_1.txt file2_1.txt > file3_1.txt
1
2
3
4
5
1
2
3
4
5
6
7
8
9
10
所以问题就是直接倒出的最后一行没有换行符,在linux里出现了少一行的现象。
一定要搞一下cat file1.txt | col -b > file1_1.txt
但是在搞bed file 的时候,新问题出现了,按照上面的方式,解决了换行的问题,去掉了 ^M, 看似问题解决了,但是在bedtools 里bed file被识别出现error。
所以又找了一些网上介绍的解决办法:
sed -e "s/\^M//" filename > newfilename
#Note: To enter ^M, type CTRL-V + M. That is, hold down the CTRL key then press V and M in succession.
例如
sed -e "s/\CTRL-V + M//" diff.ATAC.cpm2p7.txt.bed > diff.ATAC.cpm2p7.bed
注意一定要存一个新的名字,要不然就废了。
所以,当有一个bed file要看
-
wc -l XXX.bed
查看bed file 有多少行, -
cat -v XXX.bed
来看最后一行的最后一个是不是有换行符号,如果没有, 进行下一步, -
sed -e "s/\CTRL-V + M//“ XXX.bed > YYY.bed
, 之后再检查1,2两步对YYY.bed, 行数应该+1