0

I need to replace "^~^" with a tab ("t") in a CSV file in Powershell. I tried escaping caret with a backtick(^~`^) but it doesn't work. How do I do this?

$file=Import-Csv $dataFilePath

$file -replace "^~^", "`t"

  • 1
    As you are specifying a regular expression, I'd give \^ a try… inside the regex the escape character is a backslash, in powershell it's the backtick. – Peter Schneider Nov 02 '18 at 17:44
  • 1
    user the `[regex]::Escape()` method to add the needed escape chars for you. _much_ easier than doing it by hand ... [*grin*] – Lee_Dailey Nov 02 '18 at 18:31

1 Answers1

0

Is that what you're looking for?

 >$s = "^~^"
 >$s -replace "\^\~\^", "``t"
 `t

Hope that helps.

Moerwald
  • 9,219
  • 7
  • 35
  • 71