Computing.Net > Forums > Programming > Copy certain lines from a text file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Copy certain lines from a text file

Reply to Message Icon

Name: krishna_77
Date: April 11, 2009 at 01:10:43 Pacific
OS: Windows XP
Subcategory: Batch
Comment:

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.



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: April 11, 2009 at 01:26:44 Pacific
Reply:

Post several lines of the txt file and the table.


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

M2


0

Response Number 2
Name: krishna_77
Date: April 11, 2009 at 01:35:46 Pacific
Reply:

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.


0

Response Number 3
Name: krishna_77
Date: April 12, 2009 at 04:08:57 Pacific
Reply:

Hi

Am waiting for help..


0

Response Number 4
Name: Mechanix2Go
Date: April 12, 2009 at 04:43:06 Pacific
Reply:

I'm working on it but it's resisting valiantly.


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

M2


0

Response Number 5
Name: Razor2.3
Date: April 13, 2009 at 09:47:50 Pacific
Reply:

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]


0

Related Posts

See More



Response Number 6
Name: krishna_77
Date: April 14, 2009 at 07:39:05 Pacific
Reply:

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...



0

Response Number 7
Name: Mechanix2Go
Date: April 15, 2009 at 01:21:39 Pacific
Reply:

R2 strikes again


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

M2


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Copy certain lines from a text file

Delete blank lines from a text file www.computing.net/answers/programming/delete-blank-lines-from-a-text-file/14525.html

Extract Lines from a Text File www.computing.net/answers/programming/extract-lines-from-a-text-file/13817.html

Search for a line in a text file www.computing.net/answers/programming/search-for-a-line-in-a-text-file/19293.html