Copy certain lines from a text file

April 11, 2009 at 01:10:43
Specs: Windows XP
I have a text file containing 10000 lines. I have a table which shows which lines need to be copied to which file. the text length is approx 600 characters and also has special characters
Please help me with a solution for this.

See More: Copy certain lines from a text file

Report •


#1
April 11, 2009 at 01:26:44
Post several lines of the txt file and the table.


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#2
April 11, 2009 at 01:35:46
sorry will not be able to share the data of the file, however the table looks like this

text1.txt, 3
text2.txt, 4
text4.txt, 8
This is a CSV file/XLS file

and so on
the summation of all the lines is equal to 10000.

the text file is to be read and the text1.txt should contain the first 3 lines,text2.txt should contain the next 4 lines and so on..

There is no correalation between the Lines in the master file nad the name of the files.


Report •

#3
April 12, 2009 at 04:08:57
Hi

Am waiting for help..


Report •

Related Solutions

#4
April 12, 2009 at 04:43:06
I'm working on it but it's resisting valiantly.


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#5
April 13, 2009 at 09:47:50
It doesn't seem that hard. Especially in VBScript.
Set fso = CreateObject("Scripting.FileSystemObject")
Set csv = fso.OpenTextFile("input.csv")
Set data = fso.OpenTextFile("data.txt")

Do Until csv.AtEndOfStream
  line = Split(csv.ReadLine, ",")
  cnt = Trim(line(1))
  With fso.OpenTextFile(Trim(line(0)), 2, True)
    For i = 1 To cnt
      If data.AtEndOfStream Then
        WScript.Echo "Error: Data.EoF reached before Csv.EoF"
        Exit Do
      End If
      .WriteLine data.ReadLine
    Next 'i
  End With
Loop
'[EoS]


Report •

#6
April 14, 2009 at 07:39:05
Gosh.... It really worked. 'am not talking whether it worked in VB, just renamed the files and pasted the script in Excel macro and ran the macro. Got all the files

Thanks a ton...



Report •

#7
April 15, 2009 at 01:21:39
R2 strikes again


=====================================
If at first you don't succeed, you're about average.

M2


Report •


Ask Question