Cannot display a large record(Ex:more than 5000 characters)

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
btibti2013
Posts: 5
Joined: 21 Oct 2013 10:50

Cannot display a large record(Ex:more than 5000 characters)

#1 Post by btibti2013 » 21 Oct 2013 10:55

0 down vote

Hi,

I've a file with record exceeding 5000 characters i use a .bat file to read the records but i cannot. I give the file name as a parameter to the . bat and the echo !temp! or echo %%a are empty . Is there any size limitation on the variable used in FOR or echo commands ?

@echo off
SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION set filename=nothing

SET i=0

for /f "usebackq tokens=*" %%a IN (%~1) DO (

echo %%aa set temp=%%~a echo !temp! echo !temp:~0,1000!>>a

)

Thanks for your help.

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Cannot display a large record(Ex:more than 5000 characte

#2 Post by ShadowThief » 21 Oct 2013 12:59

I'm assuming the formatting got messed up when you didn't use the [ code] tags and it should actually look like

Code: Select all

@echo off 
SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION

set filename=nothing
SET i=0

for /f "usebackq tokens=*" %%a IN (%~1) DO (
   echo %%a
   set temp=%%~a
   echo !temp!
   echo !temp:~0,1000!>>a
)


String length limit is 8191 characters. What system are you using? Strings of 5005 characters both echo to the command window and the first 1000 characters get appended to a file when I'm trying your script on Windows 7.

btibti2013
Posts: 5
Joined: 21 Oct 2013 10:50

Re: Cannot display a large record(Ex:more than 5000 characte

#3 Post by btibti2013 » 21 Oct 2013 13:55

Thge system is: Windows 7 Entreprise 64bit Service Pack1.

I have a file which can contains record with 40000 characters, i have to split it file into sub files by sections , the file looks like:

/*START SECTION 1*/
blabla....
blabla..
..
/*END SECTION 1*/
/*START SECTION 2*/
blabla....
blabla..
..
/*END SECTION 2*/
/*START SECTION 3*/
blabla....
blabla..
..
/*END SECTION 2*/
/*START SECTION n*/
blabla..
..
/*END SECTION n*/

the containts of the sub file should be like (for example)

/*SECTION A*/
blabla....
blabla..
..
/*END SECTION A*/


So i made a .bat here it is:

@echo off
SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION
set filename=nothing

SET i=0

for /f "usebackq tokens=*" %%a IN (%~1) DO (
echo %%a

if "%%a"=="/*START *SECTION 1*/" (
set filename=export_SECTION.tmp
)

if "%%a"=="/*START *SECTION 2*/" (
set filename=export_SECTION2.tmp
)
.
.
.
echo !filename!
echo %%a >> !filename!

set /a i+=1
set i
)

it works fine for records which length near 2000 but if records length get bigger the echo %%a display empty string and the related record is not writ in the sub file.

Many Thanks

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Cannot display a large record(Ex:more than 5000 characte

#4 Post by foxidrive » 22 Oct 2013 01:09

This uses a helper batch file called `findrepl.bat` from - https://www.dropbox.com/s/rfdldmcb6vwi9xc/findrepl.bat

Place `findrepl.bat` in the same folder as the batch file.

It will extract the section to the console.

Code: Select all

type "file.ext" | findrepl "\/\*START SECTION 1\*\/" /e:"\/\*END SECTION 1\*\/"



If you need further help to extract the sections, then describe the actual file makeup.

btibti2013
Posts: 5
Joined: 21 Oct 2013 10:50

Re: Cannot display a large record(Ex:more than 5000 characte

#5 Post by btibti2013 » 22 Oct 2013 06:39

Thanks for your response.
I try to run the findrepl.bat but it gives me "'findrepl.bat' is not recognized as an internal or external command,
operable program or batch file."

also i don't know how should i replace the " E:"?

if "%~1" neq "" if "%~1" neq "/?" goto begin
< "%~F0" CScript //nologo //E:JScript "%~F0" "^<usage>" /E:"^</usage>" /O:+1:-1
goto :EOF
:begin
CScript //nologo //E:JScript "%~F0" %*
exit /B %errorlevel%
:end

Thanks

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Cannot display a large record(Ex:more than 5000 characte

#6 Post by foxidrive » 22 Oct 2013 10:08

btibti2013 wrote:I try to run the findrepl.bat but it gives me "'findrepl.bat' is not recognized as an internal or external command,
operable program or batch file."


Get `findrepl.bat` from - https://www.dropbox.com/s/rfdldmcb6vwi9xc/findrepl.bat

Place `findrepl.bat` in the same folder as the batch file.

btibti2013
Posts: 5
Joined: 21 Oct 2013 10:50

Re: Cannot display a large record(Ex:more than 5000 characte

#7 Post by btibti2013 » 22 Oct 2013 19:36

Many thanks it works fine now!

but i've to delete the first and the last line of a file how?

Endoro
Posts: 244
Joined: 27 Mar 2013 01:29
Location: Bozen

Re: Cannot display a large record(Ex:more than 5000 characte

#8 Post by Endoro » 22 Oct 2013 21:00

remove the first and the last line of a text file:

Code: Select all

type text.txt|findrepl /o:2:-2

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Cannot display a large record(Ex:more than 5000 characte

#9 Post by foxidrive » 23 Oct 2013 01:01

If it is the same information you need to process, then add the /o switch section at the end.

Code: Select all

type "file.ext" | findrepl "\/\*START SECTION 1\*\/" /e:"\/\*END SECTION 1\*\/" /o:+1:-1

btibti2013
Posts: 5
Joined: 21 Oct 2013 10:50

Re: Cannot display a large record(Ex:more than 5000 characte

#10 Post by btibti2013 » 23 Oct 2013 03:46

Yes! :) it works that's what i'am looking for thanks. I need to split the extracted file into sub files which contains n records each of them. :roll:

kvsblogs
Posts: 4
Joined: 04 Nov 2013 13:11

Re: Cannot display a large record(Ex:more than 5000 characte

#11 Post by kvsblogs » 04 Nov 2013 16:11

Hi,

Could some one help..I am almost running into similar problem explained above. Trying to read a txt file of 4GB size.
The txt file only has a small string "This is just a sample line appended to create a big file. " appended to a big file of size 4 GB.

am using below to read the above (dummy) txt file

for /f "tokens=* delims=" %%x in (dummy.txt) do echo %%x

if the dummy file is just 1 GB I can see the display, when the size increases the script just display blank screen.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Cannot display a large record(Ex:more than 5000 characte

#12 Post by foxidrive » 04 Nov 2013 16:43

For-In-Do can't read files past around 1 GB in size.

Explain what you need to achieve, and provide some details.

kvsblogs
Posts: 4
Joined: 04 Nov 2013 13:11

Re: Cannot display a large record(Ex:more than 5000 characte

#13 Post by kvsblogs » 04 Nov 2013 16:52

I just need to read dummy large file usually (>10GB) to monitor my system processing read time.
For which I have created a dummy txt file that appends a string to create a large file and then read that file.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Cannot display a large record(Ex:more than 5000 characte

#14 Post by foxidrive » 04 Nov 2013 16:55

You need to read a file larger than 1 GB?

Why do you need to use for-in-do and what is the purpose of reading the file?

kvsblogs
Posts: 4
Joined: 04 Nov 2013 13:11

Re: Cannot display a large record(Ex:more than 5000 characte

#15 Post by kvsblogs » 04 Nov 2013 17:11

Yes need very large files to capture the system time taken to read the large files.
I am pretty new to batch script, I used for-in-do as I only found that command for reading the contents from file. If there is any other command that would do the read job, could you suggest any?

Post Reply