Page 1 of 1

plz help me now! read and show text ?

Posted: 05 Dec 2014 02:11
by sonyman
i have a text file : a.txt
C:\Users\SonyMan\Desktop\toolbox\dragdrop_apk_editor\smali_time.132306

i want read string "132306" and show it

thank!!! :roll:

Re: plz help me now! read and show text ?

Posted: 05 Dec 2014 05:36
by dbenham

Code: Select all

@echo off
for /f "delims=" %%F in (a.txt) do for /f "delims=." %%N in ("%%~xF") do @echo %%N

Re: plz help me now! read and show text ?

Posted: 05 Dec 2014 06:27
by Yury

Code: Select all

@for /f %%i in ('"<a.txt set /p x=& call set /a %%x:*.=%%"') do @echo %%i

Re: plz help me now! read and show text ?

Posted: 05 Dec 2014 08:27
by Squashman
Just an FYI for the original poster.
For just one line the time difference is fairly trivial. Dave's code is still faster but not by much.

But if you wrap them in a FOR /L and make each set of code execute 10,000 times, Dave's code is considerably faster. We are talking by several minutes.

The CALL slows down Yury's code. Also you would not be able to use Yury's code if your input file had more than one line in your input file.

Re: plz help me now! read and show text ?

Posted: 05 Dec 2014 15:11
by foxidrive
This is all you need:

Code: Select all

@echo off
for /f "usebackq delims=" %%a in ("a.txt") do echo %%~xa

Re: plz help me now! read and show text ?

Posted: 05 Dec 2014 15:52
by dbenham
foxidrive wrote:This is all you need:

Code: Select all

@echo off
for /f "usebackq delims=" %%a in ("a.txt") do echo %%~xa

Not quite :P That includes the unwanted dot from the extension. That is why I have an extra loop.

Re: plz help me now! read and show text ?

Posted: 05 Dec 2014 16:17
by foxidrive
dbenham wrote:Not quite :P That includes the unwanted dot from the extension. That is why I have an extra loop.

yeah, good point.

Re: plz help me now! read and show text ?

Posted: 05 Dec 2014 18:23
by Yury
One more way:

Code: Select all

@for /f %%i in ('cmd /u /c type "a.txt"^| more^| findstr [0-9]') do @<nul set /p=%%i
.

Re: plz help me now! read and show text ?

Posted: 05 Dec 2014 18:48
by dbenham
Yury wrote:One more way:

Code: Select all

@for /f %%i in ('cmd /u /c type "a.txt"^| more^| findstr [0-9]') do @<nul set /p=%%i
.

This assumes numbers never appear anywhere else in the path - probably not a good assumption.

Re: plz help me now! read and show text ?

Posted: 05 Dec 2014 23:15
by sonyman
thank for all!!
this here folderpath if i want read and show folder name "smali_time.132306" how to do?

Re: plz help me now! read and show text ?

Posted: 06 Dec 2014 04:11
by Yury

Code: Select all

@for /f "usebackq delims=" %%i in ("a.txt") do @echo %%~nxi