Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.
for %%a in ("*.txt") do type %%a >> outfile.out@echo offsetlocal enabledelayedexpansionfor /f "tokens=*" %%a in (outfile.out) do ( set line=%%a echo !line:~0,30!>> Final.out )
this is a song!in love ABC
this is a song love
I have .bat file:Code: [Select]for %%a in ("*.txt") do type %%a >> outfile.out@echo offsetlocal enabledelayedexpansionfor /f "tokens=*" %%a in (outfile.out) do ( set line=%%a echo !line:~0,30!>> Final.out )
@ECHO OFFSETLOCAL ENABLEDELAYEDEXPANSIONfor %%a in ("*.txt") do type %%a >> outfile.txtfor /f "delims== tokens=*" %%a in (outfile.txt) do ( set line=%%a echo !line!>> Final.txt )
change the ECHO line to !line! only
@echo offset script="%TEMP%\stringslice.vbs"echo wscript.echo mid(wscript.arguments(0), (wscript.arguments(1)+1),wscript.arguments(2))>%script%for %%a in ("*.txt") do type "%%a" >> outfile.outfor /f "tokens=*" %%b in (outfile.out) do ( for /f "delims==" %%c in ( 'cscript //nologo %script% "%%b" 0 30' ) do echo %%c>>final.out )del %script%
@echo offset script="%TEMP%\stringslice.vbs"echo wscript.echo mid(wscript.arguments(0), (wscript.arguments(1)+1),wscript.arguments(2))>%script%for %%a in ("*.txt") do type "%%a" >> outfile.outfor /f "tokens=*" %%b in (outfile.out) do for /f "delims==" %%c in ( 'cscript //nologo %script% "%%b" 0 30' ) do echo %%c>>final.outdel %script%
@echo offset script="%TEMP%\stringslice.vbs"echo wscript.echo mid(wscript.arguments(0), (wscript.arguments(1)+1),wscript.arguments(2))>%script%for /f "tokens=1,2 delims=:" %%a in ('findstr /R "." *.txt') do ( for /f "delims==" %%c in ( 'cscript //nologo %script% "%%b" 0 30') do ( echo %%c>>final.out ))del %script%
@echo offset script="%TEMP%\stringslice.vbs"echo wscript.echo mid(wscript.arguments(0), (wscript.arguments(1)+1),wscript.arguments(2))>%script%for /f "tokens=1,2 delims=:" %%a in ('findstr /R "." *.txt') do for /f "delims==" %%c in ( 'cscript //nologo %script% "%%b" 0 30') do echo %%c>>final.outdel %script%
wscript.echo mid(wscript.arguments(0), (wscript.arguments(1)+1),wscript.arguments(2))
for /f "tokens=1,2 delims=:" %%a in ('findstr /R "." *.txt') do for /f "delims==" %%c in ( 'cscript //nologo %script% "%%b" 0 30') do echo %%c>>final.out
set longstring=This is a long stringfor /f "delims==" %%a in ( 'cscript //nologo stringslice.vbs "%longstring%" offset length' ) do set substring=%%a
for ( loop *.txt ) do ( echo substr(line,0,30))
Set objFS=CreateObject("Scripting.FileSystemObject")strFolder = "c:\test"Set objFolder = objFS.GetFolder(strFolder)Go (objFolder)Sub Go(objDIR) If objDIR <> "\System Volume Information" Then For Each eFolder in objDIR.SubFolders Go eFolder Next End If For Each strFile In objDIR.Files name =strFile.Name If objFS.GetExtensionName(strFile) = "txt" Then Set objFile = objFS.OpenTextFile(name) Do Until objFile.AtEndOfStream strLine = objFile.ReadLine WScript.Echo Mid(strLine,1,30) Loop Set objFile = Nothing End If Next End Sub
c:\test> cscript /nologo myscript.vbs
C:\test>gawk "{print substr($0,1,30)}" *.txt
its very slow because the batch has 3 for loops.... The first loop iterates a text file with 3000 lines and save to an output file. then the second loop does that 3000 times and the next loop as well...furthermore, with many text files...you do your own maths....
a more efficient approach is to read those text files 1 time only
@echo offset script="%TEMP%\stringslice.vbs"echo wscript.echo mid(wscript.arguments(0), (wscript.arguments(1)+1),wscript.arguments(2))>%script%REM For each line output by findstr /R "." *.txt, in the format filename:lineREM put the part after the colon into %%bREM (This is equivalent to running type on every .txt file in the folder)REM This is gh0std0g74's "one time only" file read.for /f "tokens=1,2 delims=:" %%a in ('findstr /R "." *.txt') do ( REM Put the first 30 characters into %%c for /f "delims==" %%c in ( 'cscript //nologo %script% "%%b" 0 30') do ( REM Append these as a new line to a file echo %%c>>final.out ) )
He's playing a game called IRL. Great graphics, *censored* gameplay.
And you needed to repeat that post even though it was the most recent post?
huh?
Quotethis is a song!in love ABC Final.out: Quotethis is a song love .out file loss 3 character "!in"
I don't think all my suggested solutions do that, actually....Didn't you notice my further examples which specifically avoid temp files? I actually mentioned this explicitly.
Code: [Select]....for /f "tokens=1,2 delims=:" %%a in ('findstr /R "." *.txt') do ( REM Put the first 30 characters into %%c for /f "delims==" %%c in ( 'cscript //nologo %script% "%%b" 0 30') do (....
....for /f "tokens=1,2 delims=:" %%a in ('findstr /R "." *.txt') do ( REM Put the first 30 characters into %%c for /f "delims==" %%c in ( 'cscript //nologo %script% "%%b" 0 30') do (....
there's still no reason to invoke cscript 3000 * n times for each lines of each text file