how to remove first two lines from txt file? 
Author Message
 how to remove first two lines from txt file?

hi folks,

still very much a newbie to scripting...

have need to remove (top) first 2, 3, or 4 lines
from a textfile... number of lines depends on
file being processed...

also have same need for the bottom 5, 6 lines...

would appreciate very much any helpful
examples of how to do this is vb script...

many thanks and regards,

hank

  --------== Posted Anonymously via Newsfeeds.Com ==-------
     Featuring the worlds only Anonymous Usenet Server
    -----------== http://www.*-*-*.com/ ==----------



Tue, 15 Apr 2003 00:58:19 GMT  
 how to remove first two lines from txt file?


Quote:
> hi folks,

> still very much a newbie to scripting...

> have need to remove (top) first 2, 3, or 4 lines
> from a textfile... number of lines depends on
> file being processed...

> also have same need for the bottom 5, 6 lines...

> would appreciate very much any helpful
> examples of how to do this is vb script...

Here's some pseudo code for you that you can translate
into VBScript:

Dim iLineCount
Dim iCurLine

-Create FSO object
-Open text file for reading

' Get line count
-Do while not at end of text file
   iLineCount = iLineCount + 1
-Loop

-Create a temp text file for writing
-Do while not at end of text file

  ' Get the first 4 lines or so
  - If iCurLine < 4 then
     - write the line to the temp text file
  - End If

  ' Get the last 6 lines or so
  - If iCurLine > iLineCount - 6 then
     - write the line to the temp text file
  - End If

  - iCurLine = iCurLine + 1
-Loop

-close both files
' The temp text file has the lines you need

-Chad



Tue, 15 Apr 2003 02:01:54 GMT  
 how to remove first two lines from txt file?

The example removes the first 2 and the last 2 lines.  Just add logic that decides what nFirst and
nLast should be...

set fso = createobject("scripting.filesystemobject")
set ts = fso.opentextfile("c:\test.txt")
arLines = split(ts.readall,vbcrlf)
ts.close
Const ForWriting = 2
set ts = fso.opentextfile("c:\test.txt",ForWriting)
nFirst = 2
nLast = ubound(arLines) -2
for n = nFirst to  nLast
    ts.writeline arLines(n)
next

--
Michael Harris
Microsoft.MVP.Scripting
--

Quote:

> hi folks,

> still very much a newbie to scripting...

> have need to remove (top) first 2, 3, or 4 lines
> from a textfile... number of lines depends on
> file being processed...

> also have same need for the bottom 5, 6 lines...

> would appreciate very much any helpful
> examples of how to do this is vb script...

> many thanks and regards,

> hank

>   --------== Posted Anonymously via Newsfeeds.Com ==-------
>      Featuring the worlds only Anonymous Usenet Server
>     -----------== http://www.newsfeeds.com ==----------



Tue, 15 Apr 2003 09:33:06 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Help Removing Lines From TXT Files.

2. Combining two files (Copy file1.txt + file2.txt)

3. Combining two files (Copy file1.txt + file2.txt)

4. Removing Line based on First Character

5. retrieving txt file contents line by line

6. retrieving txt file contents line by line

7. Reading first record of txt file??

8. Help: How to remove duplicate value llines from txt file

9. Help: How to remove duplicate value llines from txt file

10. Repost: Removing EOF char from txt file

11. Removing EOF char from txt file

12. remove rtf encoding from txt files

 

 
Powered by phpBB® Forum Software