Google Groups no longer supports new usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Work with a long line (32000) of a text file

44 views
Skip to the first unread message

alber...@gmail.com

unread,
10 Oct 2012, 06:51:4710/10/2012
to
Hi!

I have too many files with some lines, and one of they have a length of 32000 (with spaces). I'm trying to get a substring of this line to compare it and edit this if it's necesary.

I'm try to use something like this:

@echo off
setLocal EnableDelayedExpansion
dir /B |findstr ".file$">files.txt
for /F %%f in (files.txt) do (
echo.
echo File: %%f
echo -----------------------------
for /F "delims=" %%l in (%%f) do (
set line=%%l
echo !line:~0,2!
)
echo -----------------------------
)
del files.txt
endLocal

But the line with length 32000 wasn't printed.

Hope you can help me a little!

Regards.

foxidrive

unread,
10 Oct 2012, 07:00:0110/10/2012
to
CMD has a line length limit of 8KB in XP, and only 2KB in W2K.
FIND and FINDSTR also have line length limits.


Can you describe your task again, I couldn't quite grasp what you are trying to do.

It seems that you have a lot of text files and inside some of the text files are lines that exceed 32
KB. You wish to find the lines that exceed 32,000 characters, is that right?


--
foxi

alber...@gmail.com

unread,
10 Oct 2012, 07:15:4210/10/2012
to
>
>
> CMD has a line length limit of 8KB in XP, and only 2KB in W2K.
>
> FIND and FINDSTR also have line length limits.
>
>
>
>
>
> Can you describe your task again, I couldn't quite grasp what you are trying to do.
>
>
>
> It seems that you have a lot of text files and inside some of the text files are lines that exceed 32
>
> KB. You wish to find the lines that exceed 32,000 characters, is that right?
>
>
>
>
>
> --
>
> foxi

Exactly. At least one of the lines of each file hace a length of 32000 characters.

foxidrive

unread,
10 Oct 2012, 08:15:4110/10/2012
to
On Wednesday 10/10/2012 22:15, alber...@gmail.com wrote:
>> It seems that you have a lot of text files and inside some of the text files are lines that exceed 32
>> KB. You wish to find the lines that exceed 32,000 characters, is that right?
>>
>
> Exactly. At least one of the lines of each file hace a length of 32000 characters.

I cobbled together some VBS scripts that I found as batch alone is unsuited for this task.

This reports the filenames and the first line number that exceeds 32000

Execute it with: findlines.bat "c:\data folder"
and it will search the current folder and subdirectories.


@echo off
if "%~1"=="" (
echo finds files with lines greater than 32,000 characters
echo SYNTAX: "%~nx0" [path]
pause
goto :EOF
)

(
echo Dim strPath
echo Set oFSO = CreateObject^("Scripting.FileSystemObject"^)
echo strPath = "%~1"
echo ' strPath = InputBox^("Enter Folder Path: "^)
echo ' Set fOut = oFSO.CreateTextFile^("%fileout%", True^)
echo DoStuff oFSO.GetFolder^(strPath^).Path
echo Sub DoStuff^(sDir^)
echo Set oDir = oFSO.GetFolder^(sDir^)
echo For Each i In oDir.Files

echo set fso=createobject("Scripting.Filesystemobject"^)
echo set tfin=fso.OpenTextFile(sDir + "\" + i.Name, 1^)
echo dontprint=0: linenum=0
echo Do While Not tfin.AtEndOfStream
echo linenum=linenum+1
echo line=(tfin.ReadLine^)
echo if (len(line^) ^> 32000 and dontprint=0^) then wscript.echo ^
"first line: " ^& linenum ^& " - " ^& sDir + "\" + i.Name ^
:dontprint=1
echo Loop

echo Next
echo For Each i In oDir.SubFolders
echo DoStuff i.Path
echo Next
echo End Sub
)>"%temp%\vbsfiledate.vbs"

cscript /nologo "%temp%\vbsfiledate.vbs"
del "%temp%\vbsfiledate.vbs"
:: copy "%temp%\vbsfiledate.vbs" .
pause
goto :EOF




--
foxi

Todd Vargo

unread,
11 Oct 2012, 00:42:2311/10/2012
to
That is strange, from OP's code, I thought OP was trying to display only
the first 2 characters of each line. Oh well, from OP's response, you
nailed it!

--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)
0 new messages