Computing.Net > Forums > Programming > Replace top line Batch

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.

Replace top line Batch

Reply to Message Icon

Name: macuiare
Date: December 13, 2008 at 10:50:15 Pacific
OS: Windows XP pro
CPU/Ram: AMD anthlon 64x2 2gb
Product: Asus / M2N-MX SE PLUS
Comment:

Hey, Thanks for viewing this post,

I'm wanting to replace the top line of myfle.bat, only the top line and nothing else, but it has to remove the whole top line and replace it =)

thanks



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: December 13, 2008 at 11:24:08 Pacific
Reply:

@echo off & setLocal EnableDelayedExpansion

for /f "tokens=* delims= " %%a in (myfile) do (
set /a N+=1
if !N! equ 1 (
echo suzi q > newfile
) else (
echo %%a >> newfile
)
)


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

M2


0

Response Number 2
Name: macuiare
Date: December 13, 2008 at 12:13:57 Pacific
Reply:

Thank you very much, I've seen you post alot and each time its fixed the problem, id like to say your a awesome person =) anyways thanks again =)


0

Response Number 3
Name: ghostdog
Date: December 13, 2008 at 19:18:11 Pacific
Reply:

if you want batch(XP,Win2k), you can achieve it in 3 lines


c:\> echo the_new_line > newfile.txt
c:\> more +2 file >> newfile.txt
c:\> ren newfile.txt file


0

Response Number 4
Name: BatchFreak
Date: December 13, 2008 at 22:24:08 Pacific
Reply:

Hey M2, you File only removes the top line. It doesn't do anything else. so shouldn't it go....

@echo off & setLocal EnableDelayedExpansion
ECHO new top line>newfile.txt
for /f "tokens=* delims= " %%a in (o.txt) do (
set /a N+=1
if !N! gtr 1 ( echo %%a >> newfile.txt )
)

I only Batch if possible, 2000 more lines of code, oh well.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Another Batch rename post... Auto tidy Desktop using ....



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: Replace top line Batch

Replace BLank Lines With Text www.computing.net/answers/programming/replace-blank-lines-with-text/15368.html

batch command search replace quoted www.computing.net/answers/programming/batch-command-search-replace-quoted/15879.html

Replace text with batch file www.computing.net/answers/programming/replace-text-with-batch-file/17580.html