0

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,

aschipfl
  • 33,626
  • 12
  • 54
  • 99
Dror
  • 5,107
  • 3
  • 27
  • 45
  • [The Windows command prompt is *NOT* a DOS prompt!](https://scalibq.wordpress.com/2012/05/23/the-windows-command-prompt-is-not-a-dos-prompt/) – aschipfl Mar 21 '17 at 10:26

2 Answers2

0

the way I used to get the first row (NOTE: i have not tested if this also removes other hidden chars, but I was advised it does- like CR, so please be aware) content and also remove the linefeed(=LF character) on Windows-command prompt/batch file/CMD/command is:

  for /F "delims=" %%i in (source_file.txt) do (  
      <nul (set/p z=%%i) >outputfile.txt
      goto BREAK1
    )
    :BREAK1

Immidiately Under :BREAK1 row, you continue working on with a LineFeed free outputfile.txt

(Source: https://groups.google.com/forum/#!msg/microsoft.public.win2000.cmdprompt.admin/CHS0gwjZQDA/L85IIcFcLgkJ)

Dror
  • 5,107
  • 3
  • 27
  • 45
0

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
jeb
  • 78,592
  • 17
  • 171
  • 225