Search code examples
windowsbatch-filecmdlinefeed

How to remove Linefeed (LF) from first row in a text file using a batch file


I needed a script to remove the linefeed from the first row of a text file.

Other - similar topics I've researched were confusing, and had many irrelevant or misleading responses,


Solution

  • If you only need the first line, reading with set /p is simpler than a FOR/F loop.

    setlocal EnableDelayedExpansion
    set /p line= < source_file.txt
    <nul set /p ".=!line!" > outputfile.txt