0

I have a 2GB pipe-delimited data file. I would like to use PowerShell to prepend a header to the file without creating a third file. Looking at this link, I would like to change

Get-Content inputFile1.txt, inputFile2.txt | Set-Content joinedFile.txt

to

Get-Content inputFile1.txt, inputFile2.txt | Set-Content inputFile2.txt

without creating a third file. What's the best way?

I see that it seems simple to capture data from many files into a new one. Is there a efficient way to combine files in some other way - perhaps by editing the text of the large file instead?

JosefZ
  • 28,460
  • 5
  • 44
  • 83
Seth
  • 13
  • 1
  • 3
  • 1
    does this answer your question? https://stackoverflow.com/questions/67852305/how-to-prepend-to-a-file-in-powershell/67852426#67852426 – Santiago Squarzon May 03 '23 at 15:06
  • 2
    if you need to preserve memory / need to stream data to the output file then there is another way around __but you must have at least `inputFile2.txt` in memory__ – Santiago Squarzon May 03 '23 at 15:14
  • You could read only one file content (however order/sequence matters) as follows: `Get-Content inputFile2.txt | Out-File inputFile1.txt -APPEND` – JosefZ May 03 '23 at 15:50

0 Answers0