Powershell regex filter files -


i trying filter files using powershell, need insert new line character in between </tr><tr> break separate lines , remove lines match <tr> lots of characters bte lots of characters </tr> , save files in place. forgive me, new powershell , simple in sed must use powershell. have wrong.

get-content *.htm | foreach-object {$_ -replace '</tr><tr>', '</tr>\r\n<tr>'; $_}f get-content *.htm | foreach-object {$_ -replace '<tr>.*bte.*</tr>', ''; $_} 

so sounds need save changes original files. should able make these changes in 1 pass instead of reading files twice.

get-childitem *.htm | foreach-object {     $singlefilename = $_.fullname     (get-content $singlefilename) -replace '</tr><tr>', "</tr>`r`n<tr>" -replace '<tr>.*bte.*</tr>' | set-content $singlefilename } 

you cant read , write same file in pipe. place (get-content $singlefilename) in parenthesis whole file read @ once.

get-content $singlefilename | set-content $singlefilename 

as each line passed down pipe file left open set-content cant write it.


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -