grab specific text from a location in a file.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
chr15b
Posts: 23
Joined: 17 Jan 2012 07:59

grab specific text from a location in a file.

#1 Post by chr15b » 20 Jan 2012 11:07

Is it possible using findstr or another tool to get unknown text from a known position?


the text i need is always the 11th charactor in a file for 5 charactors.

ie aaaaaaaaaabbbbb

i need to get and use what bbbbb is.

unfortunately this text changes so i'm not able to search on what it is.

Thanks

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

Re: grab specific text from a location in a file.

#2 Post by Squashman » 20 Jan 2012 13:24

If you are parsing a text file with a for Loop you can set the loop variable to another variable and then parse the string by position. Is this unknown text on a specific line in the file? Or is the file just one line long?
http://www.dostips.com/DtTipsStringMani ... .MidString

chr15b
Posts: 23
Joined: 17 Jan 2012 07:59

Re: grab specific text from a location in a file.

#3 Post by chr15b » 25 Jan 2012 03:13

Hi, thanks for the reply. The file in question has many many lines but i'm only interested in the first row. the data is unknown but the location is fixed, it is always charactors 11-15

Cheers
Chris

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: grab specific text from a location in a file.

#4 Post by Ed Dyreen » 25 Jan 2012 04:47

'

Code: Select all

@echo off
set "var=aaaaaaaaaabbbbb"
set "var=%var:~10%" %= pos 10 =%
set "var"
pause
set /?
pause

Code: Select all

var=bbbbb

chr15b
Posts: 23
Joined: 17 Jan 2012 07:59

Re: grab specific text from a location in a file.

#5 Post by chr15b » 25 Jan 2012 05:04

Thanks for this, presumably i would use findstr to grab the first line - how do i get what it grabs to become a variable as ordinarily it echo's the result?

Thanks

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: grab specific text from a location in a file.

#6 Post by Ed Dyreen » 25 Jan 2012 05:20

'

Code: Select all

>"ou.TMP" echo.testing 1 2 3
<"ou.TMP" set /p "var="
echo.%var%

Code: Select all

testing 1 2 3

Post Reply