开发者

Powershell: Prefix string to data inside a .txt file

Hi I'm completely new to Powershell so pardon me if this question has a really simple answer.

I would like to use Powershell to look thru a textfile, get all values and prefix and post fix these values with a character.

How c开发者_开发知识库an this be done?

Thanks


To add a prefix and suffix to each line of a file (with default command aliases this would be a lot shorter, but full names are clearer):

get-content input-file | `
    foreach-object -process { "Prefix" + $_ + "Suffix" } | `
    out-file output-file

Add -encoding UTF8 to the out-file to override the default encoding (UTF-16).

To do this in place output-file will need to be a temporary file and then replace the input-file after the processing has completed or read the input file into memory.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜