Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays &引用;“规范化”;CSV文件_Arrays_Powershell_Csv - Fatal编程技术网

Arrays &引用;“规范化”;CSV文件

Arrays &引用;“规范化”;CSV文件,arrays,powershell,csv,Arrays,Powershell,Csv,我有一个CSV文件,用于呼叫服务台。根据更新次数,同一票据可能有1条、2条甚至5条记录。(一个字段不同,所有其他字段相同) 我想获取大部分重复的记录,并创建一个将差异连接到其中的记录。我以前编程过,但作为PowerShell的新手,我需要一些帮助 因此,根据我之前提出的一个问题,以下是我到目前为止的情况。假设数据如下: ID, Date, Comment 345, 1/1/16, Moss has reported a fire in the I/T Room 345, 1/1/16, Neve

我有一个CSV文件,用于呼叫服务台。根据更新次数,同一票据可能有1条、2条甚至5条记录。(一个字段不同,所有其他字段相同)

我想获取大部分重复的记录,并创建一个将差异连接到其中的记录。我以前编程过,但作为PowerShell的新手,我需要一些帮助

因此,根据我之前提出的一个问题,以下是我到目前为止的情况。假设数据如下:

ID, Date, Comment 345, 1/1/16, Moss has reported a fire in the I/T Room 345, 1/1/16, Never mind, he has sent an e-mail about it. 346, 1/2/16, Someone on the 5th floor is complaining about a man under her desk. 347, 2/1/16, Jen says she has broken the Internet. 347, 2/1/16, Douglas is very angry, we need a fix ASAP! 347, 2/1/16, Roy was playing a joke on her. Closing ticket.
$incidents = $FileList | Group-Object ID | % {
    New-Object psobject -property @{
        ID = $_.Name
        Date = $_.Group[0].Date
        Comment = ($_.Group | Select -Expandproperty Comment) -Join "`n"
    }
}  

如何从组中的第2行、第3行等中获取注释,将其连接到第一行中的注释,并写出文件?

组对象生成一个包含该组中所有项目的名称和组的对象。您可以使用以下方法提取它们并创建新对象:

ID, Date, Comment 345, 1/1/16, Moss has reported a fire in the I/T Room 345, 1/1/16, Never mind, he has sent an e-mail about it. 346, 1/2/16, Someone on the 5th floor is complaining about a man under her desk. 347, 2/1/16, Jen says she has broken the Internet. 347, 2/1/16, Douglas is very angry, we need a fix ASAP! 347, 2/1/16, Roy was playing a joke on her. Closing ticket.
$incidents = $FileList | Group-Object ID | % {
    New-Object psobject -property @{
        ID = $_.Name
        Date = $_.Group[0].Date
        Comment = ($_.Group | Select -Expandproperty Comment) -Join "`n"
    }
}  

(未测试,因为我目前在Mac上)

Group对象生成一个名为Group的对象,Group包含该组中的所有项目。您可以使用以下方法提取它们并创建新对象:

ID, Date, Comment 345, 1/1/16, Moss has reported a fire in the I/T Room 345, 1/1/16, Never mind, he has sent an e-mail about it. 346, 1/2/16, Someone on the 5th floor is complaining about a man under her desk. 347, 2/1/16, Jen says she has broken the Internet. 347, 2/1/16, Douglas is very angry, we need a fix ASAP! 347, 2/1/16, Roy was playing a joke on her. Closing ticket.
$incidents = $FileList | Group-Object ID | % {
    New-Object psobject -property @{
        ID = $_.Name
        Date = $_.Group[0].Date
        Comment = ($_.Group | Select -Expandproperty Comment) -Join "`n"
    }
}  

(没有测试,因为我目前在Mac上)

我首先会得到一个唯一ID的列表,例如:

$Ids = $FileList | Select-Object -ExpandProperty Id -Unique
然后我会查看门票列表,并为每个ID建立一个“报告”:

foreach($Id in $Ids){
  # Get all incident logs for this Id:
  $logs = $FileList | ?{$_.Id -eq $Id}

  $report = ""

  foreach($log in $logs){
    $report += $log.Date + ": " + $log.Comment + "; "
  }

  # Now you can write the text out
  $report | Out-File $Outfile -Append
}

希望这能给你一个想法。

我首先会得到一个唯一ID的列表,例如:

$Ids = $FileList | Select-Object -ExpandProperty Id -Unique
然后我会查看门票列表,并为每个ID建立一个“报告”:

foreach($Id in $Ids){
  # Get all incident logs for this Id:
  $logs = $FileList | ?{$_.Id -eq $Id}

  $report = ""

  foreach($log in $logs){
    $report += $log.Date + ": " + $log.Comment + "; "
  }

  # Now you can write the text out
  $report | Out-File $Outfile -Append
}

希望这能给你一个想法。

你是说一个字段是相同的(ID),而其他字段(日期、注释)是可变的吗?也就是说,您想对ID进行重复数据消除,并将(日期+注释)连接到一个报告中?除了注释之外,我对任何其他字段的更改都不感兴趣。所有其他字段都应该为同一ID复制,如果不是,我真的不在乎。我只使用第一条记录中的信息。我关心的只是保留在重复ID记录中的评论。整个计划听起来是个坏主意。我更担心的是It室的火灾,不管是否有人发送了关于火灾的电子邮件。忘了火灾吧——有人破坏了互联网。严重得多!。您的意思是一个字段是相同的(ID),而其他字段(日期、注释)是可变的吗?也就是说,您想对ID进行重复数据消除,并将(日期+注释)连接到一个报告中?除了注释之外,我对任何其他字段的更改都不感兴趣。所有其他字段都应该为同一ID复制,如果不是,我真的不在乎。我只使用第一条记录中的信息。我关心的只是保留在重复ID记录中的评论。整个计划听起来是个坏主意。我更担心的是It室的火灾,不管是否有人发送了关于火灾的电子邮件。忘了火灾吧——有人破坏了互联网。严重得多!;-)@TessellingHeckler-是的,我知道,但我还没有时间安装,因为我在Windows 10周年纪念日上忙着玩bash。多么疯狂的世界啊!。伙计,在这里的这两条评论和OP的样本数据之间,这个问题是无价的xD。公平地说,我确实从这个论坛的另一张海报上窃取了样本数据的想法。;-)@TessellingHeckler-是的,我知道,但我还没有时间安装,因为我在Windows 10周年纪念日上忙着玩bash。多么疯狂的世界啊!。伙计,在这里的这两条评论和OP的样本数据之间,这个问题是无价的xD。公平地说,我确实从这个论坛的另一张海报上窃取了样本数据的想法。