How to delete a line in a text file

  • Thread starter Thread starter Starsky
  • Start date Start date
S

Starsky

I have a script which contains a FOR loop to process a list of filenames in
a files called files.txt. As each of the filenames is processed, I would
like to delete the topmost line in files.txt. This would be the line which
contains the name of the file which was just processed. I have a huge list
of files to process. If I can delete the first line of the text file at the
end of each pass, it would save me from having to worry about which files
were already processed and avoid the risk of processing the same files
again. Anyone have any ideas on how to do this?
 
Starsky said:
I have a script which contains a FOR loop to process a list of filenames in
a files called files.txt. As each of the filenames is processed, I would
like to delete the topmost line in files.txt. This would be the line which
contains the name of the file which was just processed. I have a huge list
of files to process. If I can delete the first line of the text file at the
end of each pass, it would save me from having to worry about which files
were already processed and avoid the risk of processing the same files
again. Anyone have any ideas on how to do this?

- - - - - - - - - - begin screen capture - - - - - - - - - -
<Win2000> c:\cmd>type c:\temp\YourTestFile.txt
This is line 1 of your file. This is line 1 of your file.
This is line 2 of your file. This is line 2 of your file.
This is line 3 of your file. This is line 3 of your file.
This is line 4 of your file. This is line 4 of your file.
This is line 5 of your file. This is line 5 of your file.
This is line 6 of your file. This is line 6 of your file.
This is line 7 of your file. This is line 7 of your file.
This is line 8 of your file. This is line 8 of your file.

<Win2000> c:\cmd>more /e +1 c:\temp\YourTestFile.txt > c:\temp\YourNewFile.txt

<Win2000> c:\cmd>type c:\temp\YourNewFile.txt
This is line 2 of your file. This is line 2 of your file.
This is line 3 of your file. This is line 3 of your file.
This is line 4 of your file. This is line 4 of your file.
This is line 5 of your file. This is line 5 of your file.
This is line 6 of your file. This is line 6 of your file.
This is line 7 of your file. This is line 7 of your file.
This is line 8 of your file. This is line 8 of your file.
- - - - - - - - - - end screen capture - - - - - - - - - -
 
Phil Robyn wrote:
c:\cmd>more /e +1 c:\temp\YourTestFile.txt > c:\temp\YourNewFile.txt

Thanks Phil,
I never had the idea to do a more /? since in dos more hasn't even an
option to get a file param from the command line.

Does anyone know from which os/version on this works ?

BTW The /e seems to be unnecessary.
 
Matthias said:
Phil Robyn wrote:



Thanks Phil,
I never had the idea to do a more /? since in dos more hasn't even an
option to get a file param from the command line.

Does anyone know from which os/version on this works ?

From NT4.0 on.
BTW The /e seems to be unnecessary.

The '/e' is necessary in NT4.0.
 
Back
Top