以下是我想接近它(但使用PowerShell的,而不是SQL):
clear
pushd c:\myPath\myFolder\
#read in the contents of the files
$file1 = get-content("file1.txt")
$file2 = get-content("file2.txt")
#loop through each row of the whitespace separated file
$file1 = $file1 | %{
#for each line, split on whitespace characters, returning the results back in a single column
$_ -split "\s" | %{$_}
}
#compare the two files for matching data & output this info
compare-object $file1 $file2 -IncludeEqual -ExcludeDifferent | ft -AutoSize
popd
注:忽略协议,只需从使用类似的技术我们对空间的分割字符串中删除;即正则表达式,这次用替换而不是拆分。
clear
pushd c:\temp
$file1 = get-content("file1.txt")
$file2 = get-content("file2.txt")
$file1 = $file1 | %{
$_ -split "\s" | %{
$_ -replace ".*://(.*)",'$1'
}
}
$file2 = $file2 | %{
$_ -replace ".*://(.*)",'$1'
}
compare-object $file1 $file2 -IncludeEqual -ExcludeDifferent | ft -AutoSize
然而,你应该更喜欢SQL解决方案,试试这个(MS SQL服务器):
create table f1(url nvarchar(1024))
create table f2(url nvarchar(1024))
BULK INSERT f1
FROM 'C:\myPath\myFolder\file1.txt'
WITH (ROWTERMINATOR =' ', FIRSTROW = 1)
BULK INSERT f2
FROM 'C:\myPath\myFolder\file2.txt'
WITH (FIRSTROW = 1)
go
delete from f1 where coalesce(rtrim(url),'') = ''
delete from f2 where coalesce(rtrim(url),'') = ''
select x.url, x.x, y.y
from
(
select SUBSTRING(url,patindex('%://%',url)+3, len(url)) x
, url
from f1
) x
inner join
(
select SUBSTRING(url,patindex('%://%',url)+3, len(url)) y
, url
from f2
) y
on y.y = x.x
你的问题很模糊,所以很难给出任何价值的答案。 我建议的是用你选择的语言编写一个小程序,读取2个文件。 当它处理第一个文件时 - 将这些单词添加到字典对象或等价物。希望你可以使用像任何空白逻辑将被视为分隔符(新行,空格,制表符)。当你存储它时,你会修剪你不关心的东西,比如http://和https://等等。 然后你读第二个文件 - 检查(修剪的)单词是否在字典中。如果它们是,将它们插入到数据库中。 – bkr 2014-11-24 19:38:46
作为附加说明 - 我不相信-28uw.c.cr是一个有效的主机名。主机名标签不应以连字符开头或结尾 - http://en.wikipedia.org/wiki/Hostname。 – bkr 2014-11-24 19:45:31
@bkr感谢您的建议,我不负责这些主机名的有效性是我提供的文件。最终我使用sql /数据库,所以我想用sql的soe形式来比较数据。但我不确定什么是最好的。 – YelizavetaYR 2014-11-24 19:50:55