1

I searched but I did not find the answer I want.

I have an existing file that contains several lines and I want to write a line that will now be the first line.

Example : echo toto >> file.txt written at the end of the file, I want to write it at the beginning.

Only with cmd / powershell (no Cygwin or other)

Any ideas ?

Thank you :)

JJJ
  • 32,902
  • 20
  • 89
  • 102

1 Answers1

2

In DOS/CMD:

echo "toto" > TempNewFile.txt
type file.txt >> TempNewFile.txt
type TempNewFile.txt > file.txt
del TempNewFile.txt

In PowerShell

@("toto") + (Get-Content file.txt) | Set-Content file.txt
TechSpud
  • 3,418
  • 1
  • 27
  • 35