Hi.
First, sorry for my bad English...
I spent 4 hours searching soultion to this problem, on internet, cause i'm begginer at this.
Let's say i have c:\test.txt file. That file has 4 lines of text:
line1
line2
line2
qwertABC
I want to extract ABC from line 4, something like this:
set str=%findstr "ABC" c:\test.txt%
set str=%str:~-3%
but it won't work...
Sorry, if there is already another similiar post, but i didn't find one..
tnks.
assign result of findstr to variable
Moderator: DosItHelp
-
- Expert
- Posts: 80
- Joined: 04 Feb 2009 10:03
Try something like:
**Just a suggestions, hasn't been tested**
-R
Code: Select all
SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION
Find "ABC" Test.txt > %Temp%\ABCstrings
For /F %%s in (%Temp%\ABCstrings) Do (
Set "Str=%%s:~-3%
Call :DoSomethingWithString !Str!
)
Del %Temp%\ABCstrings > Nul
**Just a suggestions, hasn't been tested**
-R
Good start RElliott63,
The line with the set command needs some fixing.
How about:
Hope this helps.
The line with the set command needs some fixing.
How about:
Code: Select all
SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION
For /F "delims=" %%s in ('Find "ABC" Test.txt') Do (
Set "Str=%%s"
Set "Str=!s:~-3!"
Call :DoSomethingWithString !Str!
)
Hope this helps.