1

I have a multiple line file (about 300 - 400 lines) each line has 72 characters and i need that transformed into a single line.

Any ideas ?

observ
  • 157
  • 2
  • 4
  • 12
  • http://stackoverflow.com/questions/9575644/line-length-limit-in-xp-batch-file – SomeWittyUsername Nov 22 '12 at 15:39
  • 2
    I don't think this is really a duplicate. The link is trying to execute a long line, whereas this question is trying to concatenate multiple text lines into a long text line, presumably in an output file. – dbenham Nov 22 '12 at 18:33
  • Rewrite cmd.exe so it can do that... :-) – Aacini Nov 23 '12 at 03:39

3 Answers3

2

This is possible, assuming you want your concatenated line in one line in a text file. However, even though you can create the long line with batch, you will not be able to read the line using batch. As Electro Hacker says, you cannot create a batch environment variable longer than 8191 bytes long.

XP SET /P will preserve leading spaces from each line. But SET /P on Vista and beyond strips leading spaces.

This solution adds a space between each concatenated line.

@echo off
setlocal
set "infile=test.txt"
set "outfile=out.txt"

>"%outfile%" (
  for /f usebackq^ delims^=^ eol^= %%A in ("%infile%") do <nul set /p "=%%A "
)
dbenham
  • 127,446
  • 28
  • 251
  • 390
2

If you want to stick to standard Windows tools, PowerShell would also be an option:

-join (Get-Content foo.txt)
Joey
  • 344,408
  • 85
  • 689
  • 683
  • +1 A VBScript or JScript solution also would be trivial, though not this elegant :-) The advantage of script host is it is standard with XP, unlike PowerShell. – dbenham Nov 22 '12 at 18:58
0

You can't break a limitation of the OS, you can't break the 255 chars path in Windows, and you can't break the CMD interpreter lenght limitation, simply as that!

Sorry but you can't store that line into a var, no way, don't exist any magic, computers are logical.

But it's not the end of the world, you can do it so easy in any other lenguage, I recommend you Ruby or python (Ruby for that), it's an easy job, open a file, store the content into a var, and then do what you want, don't need any experience for that, if you need a example just comment this.

ElektroStudios
  • 19,105
  • 33
  • 200
  • 417
  • True that you cannot create a variable longer than 8191 bytes, nor can you read a line longer than 8191 bytes. But you can create a line longer than 8191 bytes in an output file - see [my answer](http://stackoverflow.com/a/13518488/1012053) – dbenham Nov 22 '12 at 18:46
  • Uhm, `cmd`'s limitations are hardly OS limitations. And you can have more than `MAX_PATH` characters in a path. – Joey Nov 22 '12 at 18:48