您的我的CSV文件是这样的
#BEGINPROPERTIES
total.candidate.create=2
duration=0:00:00.433
internal.audit.session.id=1397055568
internal.cluster.node.info=(product:enterprise,id:node796599_796601,http:"10.111.233.79:19788",jgroups:"chprapk11406-44186",contextPath:/enterprise,isCoordinator:false)
processing.batching.size=1
total.candidate=2
non.updatable.fields=error.different
internal.cluster.node.id=node796599_796601
progress.interval=1
CSVLineCount=2
default.operation=merge
total.status.error=2
#ENDPROPERTIES
"Index","Identifier","Status","TransactionType","Result","Message"
"1","Candidate|create|224568907","error","candidate.create",,"The following email address is already used by a candidate included in the database: landers.samantha@target.com.;"
在PowerShell中导入CSV时,我只需要考虑列名(“索引”),并且需要跳到#ENDPROPERTIES“。每次计数可能会有所不同,但每次我需要时都没有为行定义计数跳到“#ENDPROPERTIES”。 我如何实现这一目标?
答案 0 :(得分:1)
这样的事情:
$csvpath = "C:\deleteme.csv"
$csvContent = Get-Content -Path $csvpath
$LineNumber = $csvContent | Select-String '#ENDPROPERTIES' | Select-Object -ExpandProperty 'LineNumber'
$csvData = $csvContent | Select-Object -Skip $LineNumber | ConvertFrom-Csv