用VIM发现问题消失了,换行正确。 但如果关键词在fileB中重复出现的话,输出结果也会重复出现关键字。 请问如何避免这种重复? 文件A(关键词): ---------------------------------------- Apple Banana Can Delta ... ---------------------------------------- 文件B(文本): ---------------------------------------- define: apple get 100 Delta define: apple get 100 Delta ... ----------------------------------------- 文件C(结果): ----------------------------------------- apple Delta apple Delta -----------------------------------------
出错了,uniq不认识。 Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. All rights reserved. C:\Windows\system32>cd.. C:\Windows>cd.. C:\>D: D:\> grep -i -of fileA.txt fileB.txt | sort | uniq > fileC.txt 'uniq' is not recognized as an internal or external command, operable program or batch file. ====================================== 已经搞定了,需要安装 CoreUtils for Windows
S*I
13 楼
So you're using Windows; then why you post you question in Apple board? Unfortunately, Windows batch doesn't have an easy solution for what you want as *NIX. You probably need at least Windows Powershell.
【在 p*******9 的大作中提到】 : 出错了,uniq不认识。 : Microsoft Windows [Version 6.1.7601] : Copyright (c) 2009 Microsoft Corporation. All rights reserved. : C:\Windows\system32>cd.. : C:\Windows>cd.. : C:\>D: : D:\> grep -i -of fileA.txt fileB.txt | sort | uniq > fileC.txt : 'uniq' is not recognized as an internal or external command, : operable program or batch file. : ======================================
l*s
14 楼
probably he is running windows on top of apple hardware.Not uncommon :-),
【在 S**I 的大作中提到】 : So you're using Windows; then why you post you question in Apple board? : Unfortunately, Windows batch doesn't have an easy solution for what you : want as *NIX. You probably need at least Windows Powershell.
p*o
15 楼
keywords = set( line.strip() for line in file('A.txt') ) words = set( file('B.txt').read().replace('\n', ' ').split(' ') ) with open('C.txt', 'w') as f: f.write('\n'.join(keywords & words))
【在 p*******9 的大作中提到】 : 出错了,uniq不认识。 : Microsoft Windows [Version 6.1.7601] : Copyright (c) 2009 Microsoft Corporation. All rights reserved. : C:\Windows\system32>cd.. : C:\Windows>cd.. : C:\>D: : D:\> grep -i -of fileA.txt fileB.txt | sort | uniq > fileC.txt : 'uniq' is not recognized as an internal or external command, : operable program or batch file. : ======================================