如何从Powershell中的csv中的列解析字符串 [英] How to parse string from column in csv in Powershell
问题描述
我有一个csv配置为这样:
PK,INV_AMT,DATE,INV_NAME,注
1,123.44, 634,asdfljk,TEST 12OING 06/01/2010日期:04/10/2012
2,123.44,634,wet aaa,HI你是怎么11.11日期:01/01/2011
3,123.44,634,dfssdsdfRR ,LOOK AT ME NOW ... .HI7&&&&日期:06/11/1997
4,123.44,634,asdfsdgg,LOOK AT ME NOW ... .HI7&&&日期:03-21-2097
5,123.44,634,45746345,LOOK AT ME NOW ... .HI7&&&日期:02/18/2000
如何解析字符串后的日期 例如,第一行有字符串 我想能够从csv文件(如上面的文件)读取并解析出该日期并将其添加为csv文件中的新列。 感谢您的帮助。 p> 拆分Note属性的值(默认分隔符为空格),选择最后一个元素(-1) datetime对象。最后,将对象返回到管道($ _)。 I have a csv configured as such: How can I parse the date after the string " For example, the first row has the string " I would like to be able to read from a csv file such as the one above and parse out that date and add it as a new column in the csv file. Thanks for any help. Split the value of Note property (the default delimiter is space), select the last element (-1) and cast it to a datetime objects. Lastly, return the object back to the pipeline ($_).
这篇关于如何从Powershell中的csv中的列解析字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
> 。我需要解析该行中的
04/10/2012
'。
Import-Csv test.csv | Foreach-Object {$ _。Note = [datetime] $ _。Note.Split()[ - 1]; $ _}
PK,INV_AMT,DATE,INV_NAME,NOTE
1,123.44,634,asdfljk,TEST 12OING 06/01/2010 DATE: 04/10/2012
2,123.44,634,wet aaa,HI HOW ARE YOU 11.11 DATE: 01/01/2011
3,123.44,634,dfssdsdfRR,LOOK AT ME NOW….HI7&&& DATE: 06/11/1997
4,123.44,634,asdfsdgg,LOOK AT ME NOW….HI7&&& DATE: 03-21-2097
5,123.44,634,45746345,LOOK AT ME NOW….HI7&&& DATE: 02/18/2000
DATE
:" in the note column using powershell?TEST 12OING 06/01/2010 DATE: 04/10/2012
" in the note column. I need to parse '04/10/2012
' out of that row.Import-Csv test.csv | Foreach-Object { $_.Note = [datetime]$_.Note.Split()[-1]; $_}