Computing.Net > Forums > Programming > .bat delete first line of 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.

.bat delete first line of text file

Reply to Message Icon

Name: listenmirndt
Date: December 19, 2005 at 19:29:37 Pacific
OS: XP
CPU/Ram: 1.7 512
Comment:

I found this code on this forum : It deletes the first 4 lines of a text file, but I only want it to delete the first line... I do not understand this syntax and where to change it..

Can somone help? Thanks!

---------------------
@echo off

if %1'==' echo which file? && goto :eof

:main
set NOTfirst=
for /f %%L in (%1) do call :NOfirst %%L
goto :eof

:NOfirst
if %NOTfirst%'==Y' echo %1
set NOTfirst=Y
goto :eof

:eof
:: done
---------------------



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: December 19, 2005 at 20:43:03 Pacific
Reply:

Try this:

::=== NOfirst.bat
@echo off

if %1'==' echo which file? && goto :eof

:main

set NOTfirst=
for /f "tokens=*" %%L in (%1) do call :NOfirst %%L
goto :eof

:NOfirst

if %NOTfirst%'==Y' echo %*
set NOTfirst=Y
goto :eof

:eof
::======== DONE


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

M2


0

Response Number 2
Name: listenmirndt
Date: December 19, 2005 at 21:59:54 Pacific
Reply:

This echo out everything except the first line under command prompt, but it does not save in the text file...


0

Response Number 3
Name: Mechanix2Go
Date: December 19, 2005 at 22:16:26 Pacific
Reply:

NOfirst.bat oldfile > newfile


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

M2


0

Response Number 4
Name: ghostdog
Date: December 19, 2005 at 23:27:43 Pacific
Reply:

how about this

for /f "skip=1" %%A in (file-to-del.txt) do ( echo %%A >> newfile-firstline-deleted.txt )


0

Response Number 5
Name: Mechanix2Go
Date: December 20, 2005 at 00:58:23 Pacific
Reply:

Hi ghostdog,

I had to add tokens=* to make it work.

But it's much simpler, and therefore better, than mine.

I didn't know about SKIP.

DOOOOOHHH


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

M2


0

Related Posts

See More



Response Number 6
Name: ghostdog
Date: December 20, 2005 at 01:39:31 Pacific
Reply:

hi mechanix
oh right...i tested mine on a one word one line test file, so did not include the tokens=* option. :-)


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: .bat delete first line of text file

Delete first line of text www.computing.net/answers/programming/delete-first-line-of-text/13312.html

Delete First Line of Text www.computing.net/answers/programming/delete-first-line-of-text/13940.html

Extract First Line of Text www.computing.net/answers/programming/extract-first-line-of-text/13939.html