Computing.Net > Forums > Programming > Replace text from a 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.

Replace text from a file

Reply to Message Icon

Name: vishay23
Date: September 21, 2009 at 04:38:41 Pacific
OS: Windows XP
Subcategory: Batch
Comment:

Need to update file myfile.cmd
Myfile.cmd contains mapping
ex. net use s: \\mycomputer\d$

1. make copy of the orginial file as myfile.old
2. is there a way to search for a word and delete
the whole line and update with a new mapping.
3. how can i search different partition for the file

ECHO
set text= "net use s: \\mycomputer2\d$"
FOR /F "usebackq" %%i IN (`dir /A:D /B`) DO (
IF EXIST %%i\TEST\MYFILE.CMD (
CD %%i\TEST
ECHO %text% >> MYFILE.CMD
CD ../..
)
)



Sponsored Link
Ads by Google

Response Number 1
Name: Matt (by Mattio)
Date: September 21, 2009 at 12:01:40 Pacific
Reply:

FIRST PART. THIS IS THE SEARCH

echo DELETE RECORD
set search=
set /p find2=Name Search:
CLS
echo.
echo Search Begun...
echo.
echo.
FIND "%search%" myfile.cmd
echo.
echo Record Found, do you want to delete this record? Y/N
set YN=
set /p YN=Y/N ? :
IF %YN% == Y goto YES
IF %YN% == N goto NO
Pause

This is the DELETE PART
:YES
FINDSTR /v /i "%search%" < myfile.cmd > myfile2.cmd
DEL myfile.cmd
REN myfile2.cmd myfile.cmd
echo.
echo DONE
Pause
To point out, What this part does is take out the line and inputs it into a second file. Then the original file gets deleted. Then it renames the new file to the name of the first file. Bit confusing but it does work. There is probably another way to do it but I'm not an expert. So just remember, where the myfile2.cmd is, make sure it's differently named to your original file.

Hope that helps.

******************************************
MSN = HardstyleMatt@hotmail.co.uk
Need help? Just ask. :)
******************************************


0

Response Number 2
Name: ricardo647
Date: September 22, 2009 at 10:06:37 Pacific

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More






Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: Replace text from a file

Win32: Reading a texts from a file www.computing.net/answers/programming/win32-reading-a-texts-from-a-file/11673.html

How do I add text after a line?? www.computing.net/answers/programming/how-do-i-add-text-after-a-line/10869.html

I need to delete text from a file.. www.computing.net/answers/programming/i-need-to-delete-text-from-a-file/10738.html