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.

1 Answer 1

2

A Where-Object with a regexp should do the trick:

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

If you have anything other than letter after the '\\'s you might need to extend the search to include numbers, special characters, etc.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.