Solved Delete first 5 lines in a batch of files

December 8, 2012 at 18:22:44
Specs: Windows 7
I am looking to delete the first five lines of text files in a specific directory. I download sed for windows and create a batch file. When I run it, it deletes the lines in the command prompt but when I actually open the file the data is still there. Is there a way in batch or vbscript that can delete the first five lines in a batch of text files in a directory?

Thank you


See More: Delete first 5 lines in a batch of files

Report •

#1
December 8, 2012 at 19:40:08
✔ Best Answer
After a little more testing it looks like I can do this with sed

sed -i 1,5d c:\filetodeletefivelines.txt

thank you


Report •

#2
December 8, 2012 at 20:13:27
This uses "edlin", and I'm not sure of the maximum filesize supported under win-7 (older versions hovered around 64K, maybe now it's bigger):

@for %%a in (*) do (echo 1,5d;e) | edlin %%a

If this fails, vbscript can probably handle it. I"m lazy, I'll wait for the proverbial shoe to drop.


Report •

#3
December 8, 2012 at 20:14:09
Haha! crossed in the mail!

Report •

Related Solutions

#4
December 9, 2012 at 01:38:47
No sed, no edlin, no runs, no hits, no errors, nobody left on.

:: ===== script starts here ===============
::
:: admin.bat 2012-12-09 16:27:15.46
@echo off > newfile & setLocal enableDELAYedeXpansioN

for /f "tokens=* delims= " %%a in ('dir/b *.txt') do (
call :sub1 %%a
)
goto :eof

:sub1
for /f "tokens=* skip=5 delims= " %%i in (%1) do (
echo %%i
) >> newfile
move /y newfile %1
goto :eof
::====== script ends here =================

=====================
M2 Golden-Triangle


Report •

Ask Question