Using powershell how to replace pageBreak in a text file?

I am trying to create a text file from a text file. But the text file has pageBreaks in it. I want to remove or replace these pageBreaks in a text file. This will allow me to add pageBreaks to the word document, which I will subsequently create in the places where I really need it.

Below is the PowerShell code that I tried replacing pageBreak in a text file myself. This does not work. Since using "f" instead of pageBreak does not work.

$oldWord = "`fPage"
$newWord = "Page"

#-- replace the page breaks in the file
(Get-Content $inputFilePath) -replace '$oldWord', '$newWord' | Set-Content $inputFilePath

The character shown for pageBreak in the UltraEdit text editor is ♀ Replacing the character in UltraEdit is easy. I want to replace or remove this with Powershell.

Below is the relevant question. But it still remains unanswered regarding PowerShell code.

How to remove an unknown line break (special character) in a text file?

+4
source share
2 answers

for page breaks you can use:

[io.file]::ReadAllText( 'H:\oldFile.txt') | %{$_.replace("`f","")} >h:\newFile.txt

below snippet will work from powershell v3:

cat H:\oldFile.txt -raw | %{$_.replace("`f","")} >h:\newFile.txt
+2
source

Thanks for the question! That was interesting.

So the special form-feed character is bugger in powershell. If you repeat this, you will simply get an odd character or square if you cannot display it. But if you copy and paste it back into the powershell terminal, just move the command entry point to the top of the screen. Odd

. powershell $oldWord -replace 'REGEX_GOES_HERE', 'THING_TO_REPLACE_WITH_HERE, :

$oldWord -replace '[\f]', '' #You can also use \r for carriage return, \n for new line, \t for tab, \s for ALL whitespace

Form-Feed.

, ! !

+2

Source: https://habr.com/ru/post/1671493/


All Articles