How come you started a new thread? Like I said in the other one, you can use “get-content -raw” for multi-line regex search and replace. And use “.*?” instead of “\n” for the line break. A windows text file will have “\r\n” between lines. There may be other problems with your regex. I recommend using http://regex101.com. The last example I gave in the other thread works.
foreach ($file in $files) {
$content = get-content -raw $file
# regex may have problems
$content = $content -replace "(?ms)(SBR\*\w\*\d{2}\*)(\w*)(\*\*\*\*\*\*\w*~\s*)(.*?NM1\*\S*\*)(\S*)~",
'$1$5$3$4$5~'
set-content $file $content
}
JS,
I didn’t really understand your post from the previous thread but your solution above worked. How did you know I needed to use the Unix syntax. I spent several days trying to get this to work. Much thanks for your help!
I didn’t know you were on unix. But windows text files end lines with ‘\r\n’ and unix text files end lines with ‘\n’. (Osx text files end lines with ‘\r’.) Ironically, multi-line strings in windows powershell only have ‘\n’. None of this is usually visible. The bottom status bar in the emacs editor will give a sign of the text file type, “(Unix)”, "", or “U(Mac)”.