Computing.Net > Forums > Programming > Batch file to Find and Replace

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 to Find and Replace

Reply to Message Icon

Name: Machiavelli
Date: November 25, 2008 at 09:18:29 Pacific
OS: Windows
CPU/Ram: N/A
Product: N/A
Comment:

I have a script that I want to search through a file and add one line. It does this, but it also deletes all the lines that start with a ; (semicolon). Here is the script.

For /F "tokens=*" %%A in (C:\test.txt) Do (
Echo %%A>> C:\test.txt.tmp
If "%%A"=="PaperPaper=" (
Echo PrinterPort=\\store%STOREID%\lexmark>> C:\test.txt.tmp))
Move C:\test.txt.tmp C:\test2.txt

Not sure what I am doing wrong. I have tried to set the delmis to a random character to overwrite the defaults, but it still does the same thing.

It throws out lines that look like this:
;----------------------Here Blah blah
; MS-Test

Thanks for the help ahead of time guys.



Sponsored Link
Ads by Google

Response Number 1
Name: klint
Date: November 25, 2008 at 09:58:20 Pacific
Reply:

Try this:

For /F "tokens=* eol=" ...etc...

Now you will only skip blank lines...


0

Response Number 2
Name: Machiavelli
Date: November 25, 2008 at 10:57:18 Pacific
Reply:

Thanks, that works great. Is there a way I could get it to encompass the blank lines also? I would like to copy every single line, blank or not.


0

Response Number 3
Name: klint
Date: November 26, 2008 at 02:37:35 Pacific
Reply:

That's a little bit more difficult. Have a look at my Howto:

http://www.computing.net/howtos/sho...


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


For /l Batch Check File is Opene...



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 to Find and Replace

batch file to find and copy www.computing.net/answers/programming/batch-file-to-find-and-copy/9236.html

Batch file to start and stop servic www.computing.net/answers/programming/batch-file-to-start-and-stop-servic/15882.html

Batch File to find files www.computing.net/answers/programming/batch-file-to-find-files/17076.html