Computing.Net > Forums > Programming > Batch file - editting a 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.

Batch file - editting a text file?

Reply to Message Icon

Name: mjdavila
Date: November 10, 2008 at 07:47:44 Pacific
OS: DOS
CPU/Ram: na
Product: na
Comment:

Hi!

Need help creating a batch file.

I want to automate the modification of a input file.

I have a file thats 500+ lines (1.txt) And I want to be able to CUT the first 6 lines and move it into another file 2.txt.

So not only copy the 6 first lines into 2.txt but also delete them from 1.txt

Is there a simple way to do this?



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: November 10, 2008 at 08:16:27 Pacific
Reply:

Are you actu8ally using DOS? If so, which version?


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

M2


0

Response Number 2
Name: mjdavila
Date: November 10, 2008 at 08:19:35 Pacific
Reply:

Sorry - I guess not DOS... Windows XP SP2...


0

Response Number 3
Name: Mechanix2Go
Date: November 10, 2008 at 08:32:52 Pacific
Reply:

@echo off > 2.txt
setLocal EnableDelayedExpansion

for /f "tokens=* delims= " %%a in (1.txt) do (
set /a N+=1
if !N! leq 6 echo %%a >> 2.txt
if !N! gtr 6 echo %%a >> #
)

copy # 1.txt > nul
del #


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

M2


0

Response Number 4
Name: mjdavila
Date: November 10, 2008 at 08:40:10 Pacific
Reply:

thanks!! works great!


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







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: Batch file - editting a text file?

Batch to edit a text file www.computing.net/answers/programming/batch-to-edit-a-text-file/15894.html

Editing a Text File With a Batch www.computing.net/answers/programming/editing-a-text-file-with-a-batch/14889.html

Edit batch file while in a cmd window www.computing.net/answers/programming/edit-batch-file-while-in-a-cmd-window/19639.html