Delete part of a line from text file by batch

August 3, 2010 at 16:43:14
Specs: Windows 7

my text file contains

i need to have the names for files i.e just fs.xml,fsqq.xml,fsswres.xml

and the rest of the path is also variable which is written in the text file ,i.e the url may change but i have the url in a variable in my code.

e.g: ADDURL contains address
where ADDURL=http://xyz/abc/

now i have remove the value of my variable from lines of files .or i should get only the xml file names from file

See More: Delete part of a line from text file by batch

August 4, 2010 at 07:28:43
download sed for windows then do this

c:\test>  sed "s/.[^/]*\///g" file

GNU win32 packages | Gawk

Report •

August 4, 2010 at 15:07:47
cannot download any packages ....

I got one way around but i am fixed on number of tokens on lines >>>
Eg: the paths from test file has the xml filename on the 14th token then i can :

for /f "usebackq tokens=1-14* delims=/" %%a in (test.txt) do (
echo %%m

But i dont want the dependency for no of tokens as the path(URL) can vary in length

Report •

August 4, 2010 at 15:51:51

is there any way to get a substring from a variable?

i meant, i know we can do this to remove string value from variable::

set str=%str:the =%

How can i do it with a variable , if variable str2 contains "the "

I cannot do ::

set str=%str:%str2%=%


Report •

Related Solutions

August 5, 2010 at 07:37:31
To answer your original question, use something like...

for /f "delims=" %%a in (test.txt) do echo %%~nxa

For your other question, you'll need delayed expansion

@echo off

setlocal EnableDelayedExpansion

set str=some text ReplaceThis more text
set str2=ReplaceThis 
set str=!str:%str2%=!
echo %str%

Report •

August 5, 2010 at 10:24:46
THANKS ....:)

Report •

Ask Question