plz help me now! read and show text ?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
sonyman
Posts: 10
Joined: 25 Oct 2014 01:01

plz help me now! read and show text ?

#1 Post by sonyman » 05 Dec 2014 02:11

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:

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

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

#2 Post by dbenham » 05 Dec 2014 05:36

Code: Select all

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

Yury
Posts: 115
Joined: 28 Dec 2013 07:54

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

#3 Post by Yury » 05 Dec 2014 06:27

Code: Select all

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

Squashman
Expert
Posts: 4471
Joined: 23 Dec 2011 13:59

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

#4 Post by Squashman » 05 Dec 2014 08:27

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.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

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

#5 Post by foxidrive » 05 Dec 2014 15:11

This is all you need:

Code: Select all

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

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

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

#6 Post by dbenham » 05 Dec 2014 15:52

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.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

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

#7 Post by foxidrive » 05 Dec 2014 16:17

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

yeah, good point.

Yury
Posts: 115
Joined: 28 Dec 2013 07:54

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

#8 Post by Yury » 05 Dec 2014 18:23

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
.

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

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

#9 Post by dbenham » 05 Dec 2014 18:48

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.

sonyman
Posts: 10
Joined: 25 Oct 2014 01:01

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

#10 Post by sonyman » 05 Dec 2014 23:15

thank for all!!
this here folderpath if i want read and show folder name "smali_time.132306" how to do?

Yury
Posts: 115
Joined: 28 Dec 2013 07:54

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

#11 Post by Yury » 06 Dec 2014 04:11

Code: Select all

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

Post Reply