-2

I've got many txt files and I want to batch convert them to the standard notepad .txt format from command prompt or batch file

I thought to use type file.txt > newfile.txt but the type command is not working so I thought to use the more command but it limits the output...

EDIT: After looking around, this syntax is working:

FOR /F "eol=; tokens=2,3* delims=, " %i in (TEST.txt) do @echo %i %j %k >> Newfile.txt 

The problem is that it doesn't write blank lines, so the final total number of lines won't match... and I need to overwrite the original TEST.txt with the output...

phuclv
  • 37,963
  • 15
  • 156
  • 475
mkainz
  • 15
  • 4
  • 2
    `.txt` to standard notepad `.txt` format. Could you explain what the difference is? – michael_heath Jan 27 '18 at 11:42
  • I'm doing this because the txt files I'm managine if opened by notepad shows all content on the same line, if converted with more command shows correctly on multiple lines... – mkainz Jan 27 '18 at 11:48
  • Thanks for reply. Seems like the text files maybe ending lines with `LF` instead of `CRLF`. – michael_heath Jan 27 '18 at 12:00
  • Is there a way to fix these files with a batch script? – mkainz Jan 27 '18 at 12:10
  • 1
    Possible duplicate [Windows command to convert Unix line endings?](https://stackoverflow.com/questions/17579553/windows-command-to-convert-unix-line-endings?noredirect=1&lq=1) – michael_heath Jan 27 '18 at 12:18
  • 1
    Possible duplicate of [Windows command to convert Unix line endings?](https://stackoverflow.com/questions/17579553/windows-command-to-convert-unix-line-endings) – phuclv Jan 27 '18 at 14:56
  • Notepad breaks on LF and ignores CR. Wordpad etc break on CR. – ACatInLove Jan 27 '18 at 21:34

2 Answers2

0

I'm assuming you may have a file created Unix-like with LF line endings instead of the Windows-like CRLF line endings. If my assumption is correct you could try using this:

TYPE "file.txt" | FIND /V "" > "newfile.txt"

Type can read LF line endings and Find effectively converts them to CRLF.

Compo
  • 36,585
  • 5
  • 27
  • 39
  • With `aLFbLF`, I get output of `??CRLF`. `LF` and `CRLF` represent end of lines. I am on Win7. Although I am testing in a loop. May test more. – michael_heath Jan 27 '18 at 12:28
  • Same results with single line. Tried findstr as well but complains `FINDSTR: No search strings` with or without `/L` literal option. – michael_heath Jan 27 '18 at 12:45
0

I experienced success with unix2dos.

@echo off

for %%A in (*.txt) do (
    unix2dos "%%~A"
)

Default action for unix2dos is overwrite original file.

I advise checking that the target files have same encoding, with BOM or no BOM etc. before mass conversion.

michael_heath
  • 5,262
  • 2
  • 12
  • 22