Reputation: 153
How to delete the first line of a file using Batch?
I really need help... I've tried everything but it didn't work. :( I've tried this :
@echo off
Type test.txt | findstr /I /V /C:"So, lets remove this line" >>Test2.txt
exit
Upvotes: 5
Views: 13866
Reputation: 3683
To delete 1st line of text file:
more +1 testfile
or
for /f "skip=1 tokens=*" %i in ('type "testfile" ^| find /v /n ""') do (
REM ove prefixed line numbers:
set a=%i
set a=!a:*]=!
echo:!a!)
Tested in Win 10 cmd.
Upvotes: 0
Reputation: 743
(echo off
for /f "skip=1 tokens=1* delims=" %A in (c:\windows\win.ini) do echo %A
echo on)
Upvotes: 2
Reputation: 41234
Some tasks are clumsy with pure batch techniques (and mangles characters) - this is a robust solution and uses a helper batch file called findrepl.bat
that uses built in jscript-ing from - http://www.dostips.com/forum/viewtopic.php?f=3&t=4697
Place findrepl.bat
in the same folder as the batch file.
type "file.txt"|findrepl /v /o:1:1 >"newfile.txt"
Another method is to use more.exe
but it has limitations with the number of lines at 64K and it mangles TAB characters.
more +2 <file.txt >newfile.txt
Upvotes: 5
Reputation: 2195
You'll need to loop through your file line by line and output each line, except the first one.
From your example it looks like you might be looking for a specific string.
try this question/answer .. it might help you get you on your way.
Upvotes: 0