Click here for important information about

Delete first and last lines of a text file

August 2, 2010 at 07:17:38
Specs: WinXP Home Edition
Hello! I currently need some help with a batch code that would delete the first and last line of a text file.

I already have a batch thats joins 3 files together into a new text file. It does something like this:

Copy file 1
Copy file 2
Copy file 3
Create text file "data"
Delete file 1 2 and 3.

The batch file I need would need to erase data.txt's first and last lines and save it to a new
Text file named "assembly.txt" Any help would be gladly appreciated!


See More: Delete first and last lines of a text file

August 2, 2010 at 07:55:27
download sed for windows then do this

c:\test> sed -n "2,${$d;p}" file

GNU win32 packages | Gawk

Report •

August 2, 2010 at 18:59:48
Hi ghost. I downloaded sed, and used the code you provided. I really appreciate your help, but the code only exports a blank file named "sed" in .file format, while my other file still has it's lines.

I've been experimenting with this code:

@echo off & setlocal EnableDelayedExpansion > file2.txt
set /P row=< file.txt
for /F "skip=1 delims=" %%j in (file2.cfg) do (
set row=%%j
echo.!row!>> file2.txt

It manages to work great, and exports the file into the extension I need. The only problem is, it deletes every line of text that contains either ! ; and "

I don't really mind it deleting the lines with ; and " since that's what I exactly want out of the text file, but what bugs me is it deletes the ! character out of every line. Do you have any idea on why this is happening?

Report •

August 2, 2010 at 21:25:00
by default sed does not edit your file. you have to pipe to a temp file and rename it back to make the changes, or you can use the -i flag
c:\test>  sed -i.ext -n "2,${$d;p}" file

this says edit the file in place, and save it as extension .ext.

GNU win32 packages | Gawk

Report •
Related Solutions

Ask Question