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"
phuclv
  • 37,963
  • 15
  • 156
  • 475
  • 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
  • 2
    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
  • 10,448
  • 9
  • 43
  • 83