1

I have a file which contains values like below

10AB2CDEFG12345
10AB5CDEFG894567

From the above I want only the 4 characters(alphanumeric) after 10 which in the above case is

AB2C and AB5C.

Doing it for a set value like

set tmp=10AB2CDEFG12345
@echo %tmp:~2%

gives me AB2CDEFG12345

0

2 Answers 2

2

try this

set var=10AB2CDEFG12345
set "var=%var:~2,4%"
echo %var%

Look at help set for more help.

Sign up to request clarification or add additional context in comments.

3 Comments

+1 Didn't know it's possible. I will just edit to make it clearer.
The above worked just fine but can you help me figure out how I can run the above against a file with such values.The input should be the file name.
@Sankasu this answer is finished. Enhancing questions does not correspond to the SO rules. But you might simply make a new question.
0

Two ways of doing it:

set tmp=10AB2CDEFG12345
@echo %tmp:~2,-9%
@echo %tmp:~2,4%

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.