1

Csv file contents some thousands of rows and want to replace text within it.

MacBookPro*,*, with MacBookPro1*.*,

'*' is wildcard here. Text looks something like this

MacBookPro13,1,

This to be replaced with

MacBookPro,

I am not good at regex and need help.

3 Answers 3

1

You can directly do that in Powershell and can check in the CSV as well.

$string_var = 'MacBookPro*,*,'
$newstring_var=$string_var.Replace($string_var,'MacBookPro1*.*,')
$newstring_var

Let me know if you mean this.

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

1 Comment

I am referring * as wildcard here. Sorry I was not clear. I am not able to figure out the regex to be used.
1

Able to resolve it ...

(Get-Content $ExportCsvFilePath) -replace 'MacBookPro(.*?),(.*?),','MacBookPro,' | Set-Content -Path $ExportCsvFilePath -Force

Comments

0

If you have multiple entries in the csv file this should replace all of them.

 $oldString = 'MacBookPro*,*,'
    $newString = 'MacBookPro1*.*,'
    $originalFilePath = "EnterPathToFileHere"
    $newFilePath = "EnterNewPathToFileHere"

    [io.file]::readalltext($originalFilePath).Replace($oldString, $newString) | Out-File $newFilePath -Encoding ascii –Force

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.