Replace text from a file

September 21, 2009 at 04:38:41
Specs: Windows XP
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 ../..
)
)


See More: Replace text from a file

Report •


#1
September 21, 2009 at 12:01:40
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. :)
******************************************


Report •

#2
September 22, 2009 at 10:06:37

Report •

Related Solutions


Ask Question