我在CSV文件的单元格A2中有数据(没有标题),看起来像这样:报告日期:23年7月20日
我如何使用PowerShell从文件中读取此单元格,去掉除日期值以外的所有内容,并将其重新格式化为:年月日
我不需要从文件中读取任何其他数据,并且没有标题,但在文件的第一行中有其他数据。我无法修改源CSV。
我已经尝试了这里的例子的变体,但没有运气:get specific cell value in csv file using powershell
这将返回“WARNING:未指定一个或多个标头。以“H”开头的默认名称已用于替换任何丢失的标头。”但没有实际值。
2条答案
按热度按时间ltskdhd11#
可以将Import-Csv cmdlet与-Header参数沿着使用,以指定标头名称。由于CSV文件没有标题,因此可以提供虚拟标题名称。然后,您可以通过引用相应的标题和行来访问单元格值。
你可以这样做:
字符串
neekobn82#
我无法让@RarikmilkraiSouza脚本工作,但它确实帮助我弄清楚我需要去哪里。这是我最终得到的,它做了我需要的:
字符串