使用命令提示符进行文件比较 [英] File comparison using command prompt
问题描述
我想使用命令提示符比较两个文本文件,我使用名为abc和xyz的两个文本文件。我需要在其他文本文件中的唯一记录。但是我得到的一些字符串的输出到第二行,这将我的urls分成两个单独的行是有任何方式来比较他们,并获得在现有的文本文件中相同的格式的输出。
fc abc.txt xyz.txt> uniquetxt
abc文件包含如下数据
newsroom.associatedbank.com/News-Releases/Associated-Bank-opens-new-Minocqua-branch-5e1.aspx
newsroom.associatedbank.com/content/default .aspx?NewsAreaId = 2& SubjectId = 75
newsroom.associatedbank.com/content/default.aspx?NewsAreaId=2&SubjectId=76
newsroom.associatedbank.com/content/default.aspx?NewsAreaId = 2& SubjectId = 202
newsroom.associatedbank.com/News-Releases/Associated-Bank-finances-12M-for-retail-and-residential-projects-5dc.aspx
newsroom.associatedbank.com /News-Releases/Associated-Banc-Corp-completes-purchase-of-risk-and-benefits-consulting-firm-Ahmann-Martin-Co-5db.aspx
newsroom.associatedbank.com/News-Releases/ Associated-opens-new-Rochester-branch-5da.aspx
xyz文件包含如下数据
newsroom.associatedbank.com/News-Releases/Associated-Bank-opens-new-Minocqua-branch-5e1.aspx
newsroom.associatedbank.com/content/default.aspx?NewsAreaId=2&SubjectId=75
newsroom.associatedbank.com/content/default.aspx?NewsAreaId=2&SubjectId=76
newsroom.associatedbank .com / content / default.aspx?NewsAreaId = 2& SubjectId = 202
newsroom.associatedbank.com/News-Releases/Associated-opens-new-Rochester-branch-5da.aspx
您不必下载 从 注意: 要查看 使用 Cmdlet的别名,省略PowerShell 语句的可选部分,下一个命令应该给出相同的结果: I wanted to compare two text files using command prompt and I am using two text files with name abc and xyz. I need unique records in other text file. But the output which I get for some string are going on to second line which breaks my urls into two separate lines is there any way to compare them and get output in the same format which in the existing text file. abc File contains data as below xyz File contains data as below
You do not have to download From Notes: To see Using alias names for Cmdlets and omitting optional parts of PowerShell statements, next command should give the same result:
这篇关于使用命令提示符进行文件比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! Windows PowerShell 2.0 $
cmd.exe
命令行:
powershell Compare-Object -ReferenceObject(Get-Content abc.txt )-DifferenceObject(Get-Content xyz.txt)-IncludeEqual ^ | Out-File -FilePath unique.txt -Width 4096
-IncludeEqual
(仅限于添加);
| 管道是
^ |
转义以传递给PowerShell,而不是在 cmd
;
-Width 4096
更改为所需的输出行长度(整数范围)。任何其他字符都将被截断,不包括。如果省略此参数,则宽度由主机的特性决定。 Windows PowerShell控制台的默认值为80(字符);
SideIndicator
输出格式,请省略 ^ | Out-File ...
,如下所示。
powershell Compare-Object -ReferenceObject(Get-Content abc.txt)-DifferenceObject Get-Content xyz.txt)-IncludeEqual
powershell diff(type abc.txt)(gc xyz.txt)-includeequal
pre>
fc abc.txt xyz.txt > unique.txt
newsroom.associatedbank.com/News-Releases/Associated-Bank-opens-new-Minocqua-branch-5e1.aspx
newsroom.associatedbank.com/content/default.aspx?NewsAreaId=2&SubjectId=75
newsroom.associatedbank.com/content/default.aspx?NewsAreaId=2&SubjectId=76
newsroom.associatedbank.com/content/default.aspx?NewsAreaId=2&SubjectId=202
newsroom.associatedbank.com/News-Releases/Associated-Bank-finances-12M-for-retail-and-residential-projects-5dc.aspx
newsroom.associatedbank.com/News-Releases/Associated-Banc-Corp-completes-purchase-of-risk-and-benefits-consulting-firm-Ahmann-Martin-Co-5db.aspx
newsroom.associatedbank.com/News-Releases/Associated-opens-new-Rochester-branch-5da.aspx
newsroom.associatedbank.com/News-Releases/Associated-Bank-opens-new-Minocqua-branch-5e1.aspx
newsroom.associatedbank.com/content/default.aspx?NewsAreaId=2&SubjectId=75
newsroom.associatedbank.com/content/default.aspx?NewsAreaId=2&SubjectId=76
newsroom.associatedbank.com/content/default.aspx?NewsAreaId=2&SubjectId=202
newsroom.associatedbank.com/News-Releases/Associated-opens-new-Rochester-branch-5da.aspx
Windows PowerShell 2.0
if you have Windows 7
because it is already installed.cmd.exe
command line:powershell Compare-Object -ReferenceObject (Get-Content abc.txt) -DifferenceObject (Get-Content xyz.txt) –IncludeEqual ^| Out-File -FilePath unique.txt -Width 4096
–IncludeEqual
(added for piquancy only);|
pipe is ^|
escaped to pass it to PowerShell, not to treat it in cmd
; -Width 4096
to desired output line length (integer range). Any additional characters are truncated, not wrapped. If you omit this parameter, the width is determined by the characteristics of the host. The default for the Windows PowerShell console is 80 (characters);SideIndicator
output format, omit ^| Out-File ...
as follows. You should get truncated output on your screen.powershell Compare-Object -ReferenceObject (Get-Content abc.txt) -DifferenceObject (Get-Content xyz.txt) –IncludeEqual
powershell diff (type abc.txt) (gc xyz.txt) -includeequal