0

I have a csv file with some data. I have read the columns of it using

$read=import-csv C:\file.csv | foreach-object {"{0} {1}" -f $.ColA,$.ColB}

There are 100+ rows for this.

This is how $read looks:

test2pc K:\\
test3pc L:\\
testapc 
testapc C:\\XYZ
testapc C:\\
testapc C:\\
testapc 
testbpc C:\\
testbpc F:\\
testbpc F:\\ABC
testbpc F:\\DEF
testbpc F:\\GHI

I am looking to remove all rows except those which have anything after the "\\", and anything that does not have a "\\". I also am looking to modify those entries, in the end I would be left with

\\testapc\C$\XYZ
\\testbpc\f$\ABC
\\testbpc\F$\DEF
\\testbpc\F$\GHI

Any inputs greatly appreciated.

4

1 回答 1

2

Where-Object带有正则表达式的 A 应该可以解决问题:

$read=Import-Csv C:\file.csv | Where-Object { $_.ColB -match '\\\\\w' } | Foreach-Object {"{0} {1}" -f $.ColA,$.ColB}

如果您在 '\\'s 后面有除字母以外的任何内容,您可能需要扩展搜索以包括数字、特殊字符等。

于 2012-07-03T06:37:48.350 回答