如何將標題添加到文本文件中?

[英]How can I add the header to a text file?


How can I add the header to a top of text file using PowerShell? I have tried using the below code like:

如何使用PowerShell將標題添加到文本文件的頂部?我已經嘗試使用以下代碼:

Add-Content -Path E:\BHS_output_1.txt -Value (Get-Content "E:\header.txt")

1 个解决方案

#1


1  

Like this:

是這樣的:

$textfile   = 'E:\BHS_output_1.txt'
$headerfile = 'E:\header.txt'
$(Get-Content $headerfile; Get-Content $textfile) | Set-Content $textfile

Read the contents of header and text file after each other in a subexpression, then write the entire output back to the text file. The subexpression is required, so that reading from the text file is completed before writing starts, otherwise you'd get an access conflict.

在子表達式中逐個讀取頭文件和文本文件的內容,然后將整個輸出寫回文本文件。必須使用子表達式,以便在開始寫入之前完成文本文件的讀取,否則會出現訪問沖突。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2015/08/06/75b38edf31c653c5882cb8f5a178fd21.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com