![](/img/trans.png)
[英]Forloop not initializing the 2nd time despite initializing the 1st time when parsing the same text file
[英]terminal, diff of two files, print out all lines, which are on the 2nd file a no on 1st file
在后續示例中,每一行都可以為空或可以包含一些字符。 字符也可以不是數字。 每行也可以有換行符和制表符。
Follow 看起來部分沒問題,但不適用於更復雜的內容:
文件1.txt
1
2
3
5
文件2.txt
1
4
5
使用上面的簡單示例:
comm -1 -3 file1.txt file2.txt
4
更復雜的示例,不適合 file1.txt
0
2
3
4
5
6
7
8
10
文件2.txt
1
4
6
7
8
9
10
錯誤的 output(這個樣本上的 10 不應該在 output 上)
1
9
10
如果您以相同的方式對 file1.txt 和 file2.txt 進行排序,那么在運行示例代碼之前,您的示例代碼可以正常工作。
您可以按照以下方式進行:
sort file1.txt > file1_sorted.txt
sort file2.txt > file2_sorted.txt
之后,將上面的文件用於您的代碼:
comm -1 -3 file1_sorted.txt file2_sorted.txt
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.