Powershell Import-CSV 如何跳过基于字符串的特定行? [英] Powershell Import-CSV how to skip until particular line based on string?

查看:34
本文介绍了Powershell Import-CSV 如何跳过基于字符串的特定行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 CSV 文件是这样的

Hi My CSV file is like this

#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".我如何做到这一点?

While importing CSV in powershell, I need to consider only from Column name ( "Index") and need to skip till #ENDPROPERTIES". There are no defined count for lines as each time the count may vary but every time I need to skip until "#ENDPROPERTIES". How do I achieve that?

推荐答案

是这样的:

$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

这篇关于Powershell Import-CSV 如何跳过基于字符串的特定行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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