A
A
Alexander Pavlov2021-11-01 07:10:49
PowerShell
Alexander Pavlov, 2021-11-01 07:10:49

How to substitute characters in a file for strings and return them to another file in Powershell?

Hello.

It is necessary to take the data from one file. Substitute characters at the beginning and end of lines of text and return the finished data to another file.
Wrote like this, but only one last line is returned:

$file = Get-Content "C:\Temp\result.txt"
$pp = "PP"
$pp111 = "pp111"

foreach ($line in $file) {
    "$pp$line$pp111" | Out-File -FilePath C:\Temp\re.txt -Encoding oem
}


Example text:
spoiler
You should look at the following URL's in order to grasp a solid understanding
of Nginx configuration files in order to fully unleash the power of Nginx.
https://www.nginx.com/resources/wiki/start/
https://www.nginx.com/resources/wiki/start/topics/...
https://wiki.debian.org/Nginx/DirectoryStructure

Finished option:
spoiler
PPhttps://wiki.debian.org/Nginx/DirectoryStructurepp111


How to make it so that all changed lines are transferred?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir, 2021-11-01
@Sanchez9891


The Out-File cmdlet has the -Append parameter

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question