1

I have a .tex file in which I want to replace the string a\a{nn}o with a(nn)o

I have tried the following PowerShell (v5) code:

(Get-Content h:\combined.tex) | ForEach-Object { $_ -replace "a\a{nn}o", "a(nn)o" } `
    | Set-Content h:\combined2.tex

It runs, but nothing changes in the text. What am I doing wrong?

1
  • If Jeff's comment points to the source of the problem, then using "a\\a\{nn\}o" should fix it.
    – jpaugh
    Feb 1, 2018 at 16:00

1 Answer 1

0

I got it to work with the following:

$(Get-Content .\temp) -replace "123","ABC" | Set-Content temp2

The for loop is unnecessary, and I believe it (or the pipe) may be causing the problem

1
  • 2
    -replace uses regular expressions, which may cause problems with the querent's search and replace strings. Feb 1, 2018 at 15:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .