确定整数是否大于或等于powershell中的整数列表

时间:2016-05-31 17:09:27

标签: powershell nested-loops

我有两个数字列表,我希望将列表A与列表B进行比较,以便逐行浏览列表A并确定该数字是否小于B中的数字然后移至下一个比如B和重复。

如果发现A中的数字小于B,我希望返回A中的数字以及"匹配"从B。

我一直在尝试嵌套循环,而且还没有开始使用它。

任何有关我尝试的建议都会非常有帮助。

谢谢!

这是我的代码"如果你想把它称之为。

$chrIVsite = @("322592","425559","427431") 
$SNPCsite = @("28860","43205","279260","481810")

    foreach ($read in $chrIVsite) 
{
    foreach ($site in $SNPCsite) {
if ($_.read -le $_.SNPCsite)
    {"$_.read"+"`t"+"$_.SNPCsite"
    }
 } }
export-csv 'testing.txt' -delimiter "`t" -notype

我的预期结果是:

425559 481810

427431 481810

1 个答案:

答案 0 :(得分:0)

感谢@AnthonyStringer我只是遇到了一些简单的问题。

此代码:

$chrIVsite = @("322592","425559","427431")
$SNPCsite = @("28860","43205","279260","481810","481812","481814")

 foreach ($read in $chrIVsite)
{
 foreach ($site in $SNPCsite) {
 if ([int]$read -le [int]$site)
 {"$read"+"`t"+"$site"
 }
 } }

我的出局看起来像这样:

322592  481810
322592  481812
322592  481814
425559  481810
425559  481812
425559  481814
427431  481810
427431  481812
427431  481814