|
server
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
batch file to split multiple text files in half.Hello all,
I would first like to thank everyone who helped me with my previous problem - you guys made my life so much easier! Now I have another issue. I have a directory full of approx. 2mb text files that I need to split in half. they are .prn (text) files, and look like this: 28A41EML.PRN I would like to split this file in to two files. the first file can keep the original name, and the second could be something like 28A41EMA.PRN. our processing machines pickup and process any file that has the EML.PRN associated with it. each file contains data with each line containing data for a 5 minute period, and each file contains 1 month's worth of data each 5 minute interval is one line. If anyone can help me split these, I would be very greatful! Thank you very much in advance! -- yammyguy ------------------------------------------------------------------------ yammyguy's Profile: http://forums.techarena.in/members/88249.htm View this thread: http://forums.techarena.in/server-scripting/1175792.htmhttp://forums.techarena.in On May 7, 2:18 pm, yammyguy <yammyguy.3rt...@DoNotSpam.com> wrote:
Show quoteHide quote > Hello all, Do they need to be exactly in half? Can it be every other line in> > I would first like to thank everyone who helped me with my previous > problem - you guys made my life so much easier! Now I have another > issue. > > I have a directory full of approx. 2mb text files that I need to split > in half. they are .prn (text) files, and look like this: 28A41EML.PRN > > I would like to split this file in to two files. the first file can > keep the original name, and the second could be something like > 28A41EMA.PRN. our processing machines pickup and process any file that > has the EML.PRN associated with it. > > each file contains data with each line containing data for a 5 minute > period, and each file contains 1 month's worth of data each 5 minute > interval is one line. > > If anyone can help me split these, I would be very greatful! Thank you > very much in advance! > > -- > yammyguy > ------------------------------------------------------------------------ > yammyguy's Profile:http://forums.techarena.in/members/88249.htm > View this thread:http://forums.techarena.in/server-scripting/1175792.htm > > http://forums.techarena.in different file or do you need the first half in one and the second half in another? Here is some code that will split out every other line: @echo off for /f "delims=: tokens=1,*" %%i in ('type file.txt ^|findstr /n .') do ( echo %%j >tempfile.txt call :oddeven % %i ) goto :EOF :oddeven set /a oddeven=tempvar %%set tempvar= %1 2 if {%oddeven%} == {0} type tempfile.txt >> even.txt if {%oddeven%} == {1} type tempfile.txt >> odd.txt -irobx Home page -> http://www.irobx.net Blog -> http://www2.irobx.net:8010/serendipity/
Show quote
Hide quote
"yammyguy" <yammyguy.3rtvzb@DoNotSpam.com> wrote in message If you wish to split each file of x lines so that x/2 lines end up in one news:yammyguy.3rtvzb@DoNotSpam.com... > > Hello all, > > I would first like to thank everyone who helped me with my previous > problem - you guys made my life so much easier! Now I have another > issue. > > I have a directory full of approx. 2mb text files that I need to split > in half. they are .prn (text) files, and look like this: 28A41EML.PRN > > I would like to split this file in to two files. the first file can > keep the original name, and the second could be something like > 28A41EMA.PRN. our processing machines pickup and process any file that > has the EML.PRN associated with it. > > each file contains data with each line containing data for a 5 minute > period, and each file contains 1 month's worth of data each 5 minute > interval is one line. > > If anyone can help me split these, I would be very greatful! Thank you > very much in advance! > -- > yammyguy file and the rest ends up in the second file then this code should do it. Make sure to create a copy of the whole folder before you test the script! [01] sFolder = "D:\Thu" [02] Set oFSO = CreateObject("Scripting.FileSystemObject") [03] If oFSO.FolderExists(sFolder & "\Temp") _ [04] Then oFSO.DeleteFolder sFolder & "\Temp" [05] oFSO.CreateFolder(oFolder.Path & "\Temp") [06] Set oFolder = oFSO.GetFolder(sFolder) [07] [08] For Each oFile In oFolder.Files [09] sName1 = oFile.ParentFolder & "\Temp\" & oFile.Name [10] sName2 = oFile.ParentFolder & "\Temp\" _ [11] & Left(oFile.Name, Len(oFile.Name) - 5) & "L.prn" [12] Set oTextFile = oFSO.OpenTextFile(oFile, 1) [13] Set oOut1 = oFSO.CreateTextFile(sName1) [14] Set oOut2 = oFSO.CreateTextFile(sName2) [15] sText = oTextFile.Readall [16] aText = Split(sText, VbCrLf) [17] For i = 0 To UBound(aText) \ 2 [18] oOut1.WriteLine aText(i) [19] Next [20] For i = UBound(aText) \ 2 + 1 To UBound(aText) [21] oOut2.WriteLine aText(i) [22] Next [23] oTextFile.Close [24] oOut1.Close [25] oOut2.Close [26] Next [27] [28] For Each oFile In oFolder.Files [29] oFSO.DeleteFile oFile [30] Next [31] Set oTemp = oFSO.GetFolder(oFolder.Path & "\Temp") [32] For Each oFile In oTemp.Files [33] oFSO.MoveFile oFile, oFolder.Path & "\" & oFile.Name [34] Next Hello Pegasus, and irobx...
thanks for the information - Pegasus, is what you posted a dos
script???
Each file has a header with a months worth of data, and each day has
288 entries - 5 minute intervals each day which gives a total of 8640
lines + 1 header (which will also have to be added to the second file)
So would like to split each file from the 1st to the 15th, then the rest
gets transferred to another file with the header.
I tried uploading a copy of the file through a text file, but it kept
failing...
I have about 800 or 900 of these files - and I need to run through each
and split the files this way. Obviously manually would take for EVER!
:S
--
yammyguy
------------------------------------------------------------------------
yammyguy's Profile: http://forums.techarena.in/members/88249.htm
View this thread: http://forums.techarena.in/server-scripting/1175792.htmhttp://forums.techarena.in
Show quote
Hide quote
"yammyguy" <yammyguy.3rucnc@DoNotSpam.com> wrote in message
news:yammyguy.3rucnc@DoNotSpam.com... > > Hello Pegasus, and irobx... > > thanks for the information - Pegasus, is what you posted a dos > script??? > > Each file has a header with a months worth of data, and each day has > 288 entries - 5 minute intervals each day which gives a total of 8640 > lines + 1 header (which will also have to be added to the second file) > So would like to split each file from the 1st to the 15th, then the rest > gets transferred to another file with the header. > > I tried uploading a copy of the file through a text file, but it kept > failing... > > I have about 800 or 900 of these files - and I need to run through each > and split the files this way. Obviously manually would take for EVER! > :S > > > -- > yammyguy > ------------------------------------------------------------------------ > yammyguy's Profile: http://forums.techarena.in/members/88249.htm > View this thread: http://forums.techarena.in/server-scripting/1175792.htm > > http://forums.techarena.in >
Show quote
Hide quote
"yammyguy" <yammyguy.3rucnc@DoNotSpam.com> wrote in message You're posting in a "scripting" newsgroup, not in a "batch" newsgroup, hence news:yammyguy.3rucnc@DoNotSpam.com... > > Hello Pegasus, and irobx... > > thanks for the information - Pegasus, is what you posted a dos > script??? > > Each file has a header with a months worth of data, and each day has > 288 entries - 5 minute intervals each day which gives a total of 8640 > lines + 1 header (which will also have to be added to the second file) > So would like to split each file from the 1st to the 15th, then the rest > gets transferred to another file with the header. > > I tried uploading a copy of the file through a text file, but it kept > failing... > > I have about 800 or 900 of these files - and I need to run through each > and split the files this way. Obviously manually would take for EVER! > :S > > > -- > yammyguy > ------------------------------------------------------------------------ > yammyguy's Profile: http://forums.techarena.in/members/88249.htm > View this thread: http://forums.techarena.in/server-scripting/1175792.htm > > http://forums.techarena.in > I gave you a VB Script solution. While it might be possible to design a batch solution to do the job, it is likely to run very slowly. Here is how you test my solution: 1. Create a test folder. 2. Populate it with a few of your files. 3. Save my script as c:\yammyguy.vbs. 4. Modify line [01] to reflect te name of your test folder. 5. Remove the line numbers. 6. Save it again. 7. Double-click it to run it. If you still have a problem, don't just write "it kept failing...". This tells me next to nothing. Report exactly what happens and include all error messages you see!
Show quote
Hide quote
On May 8, 2:14 am, "Pegasus [MVP]" <n***@microsoft.com> wrote: Your description is a bit confusing. So you need to copy the 1st line> "yammyguy" <yammyguy.3ru...@DoNotSpam.com> wrote in message > > news:yammyguy.3rucnc@DoNotSpam.com... > > > > > > > Hello Pegasus, and irobx... > > > thanks for the information - Pegasus, is what you posted a dos > > script??? > > > Each file has a header with a months worth of data, and each day has > > 288 entries - 5 minute intervals each day which gives a total of 8640 > > lines + 1 header (which will also have to be added to the second file) > > So would like to split each file from the 1st to the 15th, then the rest > > gets transferred to another file with the header. > > > I tried uploading a copy of the file through a text file, but it kept > > failing... > > > I have about 800 or 900 of these files - and I need to run through each > > and split the files this way. Obviously manually would take for EVER! > > :S > > > -- > > yammyguy > > ------------------------------------------------------------------------ > > yammyguy's Profile:http://forums.techarena.in/members/88249.htm > > View this thread:http://forums.techarena.in/server-scripting/1175792.htm > > >http://forums.techarena.in > > You're posting in a "scripting" newsgroup, not in a "batch" newsgroup, hence > I gave you a VB Script solution. While it might be possible to design a > batch solution to do the job, it is likely to run very slowly. > > Here is how you test my solution: > 1. Create a test folder. > 2. Populate it with a few of your files. > 3. Save my script as c:\yammyguy.vbs. > 4. Modify line [01] to reflect te name of your test folder. > 5. Remove the line numbers. > 6. Save it again. > 7. Double-click it to run it. > > If you still have a problem, don't just write "it kept failing...". This > tells me next to nothing. Report exactly what happens and include all error > messages you see! into both files then lines 2-4321 to one and 4322-8641 into the other file? I have to agree with yammyguy that batch processing is going to be too slow when processing thousands of lines of text like this. Though find his commenting on scripting a bit contentious. NT shell scripting ( or batch file programming, if you like) is very powerful and has its place. And this is not the vbscripting group, that group is microsoft.public.scripting.vbscript. Yammyguy's code does the bulk of what you need but it doesnt seem to handle the header line. If you need help with that just holla. -irobx Home page -> http://www.irobx.net Blog -> http://www2.irobx.net:8010/serendipity/ <irobx.***@gmail.com> wrote in message
news:cdb09595-23d2-4756-8dd7-eeb551e2c99f@r34g2000vba.googlegroups.com... Your description is a bit confusing. So you need to copy the 1st line> > If you still have a problem, don't just write "it kept failing...". This > tells me next to nothing. Report exactly what happens and include all > error > messages you see! into both files then lines 2-4321 to one and 4322-8641 into the other file? ================ I assume you're replying to the OP, not to me?
Show quote
Hide quote
On May 9, 1:58 am, "Pegasus [MVP]" <n***@microsoft.com> wrote: Sorry I got the names backwards...> <irobx.***@gmail.com> wrote in message > > news:cdb09595-23d2-4756-8dd7-eeb551e2c99f@r34g2000vba.googlegroups.com... > > > > > If you still have a problem, don't just write "it kept failing...". This > > tells me next to nothing. Report exactly what happens and include all > > error > > messages you see! > > Your description is a bit confusing. So you need to copy the 1st line > into both files then lines 2-4321 to one and 4322-8641 into the other > file? > > ================ > > I assume you're replying to the OP, not to me? Just so that one can evaluate if batch or script is the right approach,
here is another script in biterscripting ( http://www.biterscripting.com
) .
Code: -------------------- # Get a list of .PRN files var str list ; lf -rn "*.PRN" > $list # Process files one by one while ($list <> "") do var str file ; lex "1" $list > $file # Read file into a variable. var str content ; cat $file > $content # How many lines does the file have ? var int lines ; set $lines = { len -e $content } ; set $lines = $lines/2 # Separate the two halves. var str half1, half2 ; lex (makestr(int($lines))+"]") $content > $half1 ; set $half2 = $content # Write the two halves. echo $half1 > $file ; var str file2 ; set $file2=$file+"_2" ; echo $half2 > $file2 done -------------------- Randir -- RandirRandwa ------------------------------------------------------------------------ RandirRandwa's Profile: http://forums.techarena.in/members/92956.htm View this thread: http://forums.techarena.in/server-scripting/1175792.htmhttp://forums.techarena.in
Set Local Computer Description
Use VBScript to Set Local Computer Description Inventory script question How do implement this wildcard? Logon script help Issues when launching a vbscript file from hta interface file how do I disjoin a machine to workgroup name Get computer name as variable to use in vbs script. anyone know if this is possible? Check if a list of user IDs exist/disabled |
|||||||||||||||||||||||