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
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.
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
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.
Summary: I am trying to delete blank lines from a text file when executing my batch file. I used the code found on this site @Echo off For /F "tokens=1 delims=" %%A in (c:\orig.txt) Do Echo %%A >> c:\new.tx...
Summary: Very simple: I'm trying to extract particular lines from a small text file. Ideally using the Windows command line to take lines 1 and 10 from one text file and output them to another text file. Thank...
Summary: Hi, I need make a batch file that would search for the line "(0 rows affected)" from a text file, if this line is found it should exit the script, else it should carry on with the rest of the script. ...