拆分字符串字段并在输出对象中重复其他字段 [英] Splitting string field and repeating other fields in output objects

查看:49
本文介绍了拆分字符串字段并在输出对象中重复其他字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要分离下面的数组数据,但想不出一个好的快速的方法来做到这一点.

I need to separate the following array data but can't think of a good and quick way to do it.

Name                              OrderGroup           OrderDate
PID365583                         FY13Q1-D             8/28/2014 12:00:00AM
PID354731,361935                  FY13Q2-D             8/28/2014 12:00:00 AM
PID354737,361937                  FY13Q3-D             11/7/2014 12:00:00 AM
PID359099,361933,363165           FY13Q4-D             11/13/2014 12:00:00 AM

每个与它相关联的数字都不止一个的名称(用逗号分隔)我需要移动到数组中的一个单独的行,并从它当前所在的数组行复制相同的信息.所以 PID354731,361935 需要分成两行,一行用于PID354731,另一行用于361935;两者都将包含相同的订单组 FY13Q2-D 和订单日期 8/28/2014 12:00:00 AM.

Every name that has more than one number associated with it (separated by commas) I need to move to a separate line in the array and copy the same info from the array line that it's currently in. So PID354731,361935 would need to be broken into two lines, one for PID354731 and one for 361935; both would contain the same ordergroup FY13Q2-D and order date 8/28/2014 12:00:00 AM.

推荐答案

假设文件数据:

foreach ($line in (Get-Content $file | select -skip 1) )
{
 $Parts = $line.split(' ',3)
  foreach ($Name in $Parts[0].split(',') )
   {
     [PSCustomObject]@{
       Name = $Name
       OrderGroup = $Parts[1]
       OrderDate = [datetime]$Parts[2]
      }
   }

 }

这篇关于拆分字符串字段并在输出对象中重复其他字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆