Page 1 of 1

remove unwanted file extension!!! help!

Posted: 03 Apr 2010 05:56
by jamesfui
hi dostips batch scripters,
is it possible to remove unwanted file extension in a text document?
for example,

ref.txt
---------------content-----------------
123.jpg
456.jpg
789.jpeg
def.bmp
ghi.bmp
jkl.pdf
abc.pdf
*.*etc
--------------content end--------------

i use the notepad replace feature & it works but for large number of
different file extensions, it is quite time consuming!! :?

can bat remove those file extension with ease???
so that the result will be as below,

ref.txt <- filter out
---------------content-----------------
123
456
789
def
ghi
jkl
abc

--------------content end--------------

thanks in advance!! :)

Re: remove unwanted file extension!!! help!

Posted: 03 Apr 2010 11:31
by !k

Code: Select all

@echo off
move ref.txt ref.bak
for /f "delims=" %%a in (ref.bak) do echo %%~na>> ref.txt

Re: remove unwanted file extension!!! help!

Posted: 04 Apr 2010 19:05
by ghostmachine4
download sed for windows at gnuwin32.sourceforge.net/packages/sed.htm

Code: Select all

sed -i.bak "s/\..*$//" file