0

I have a below line in a pom.xml file.

<abc>xyz</abc>

I need to extract xyz by doing a pattern matching using batch script same like sed -e 's/(.*)/\1/'

and the output should be xyz.

Can anyone please help?

3
  • Would Powershell be an option? Commented Nov 18, 2019 at 12:12
  • most of the bit is been done in batch. Only a small part is left. So powershell wont be an option in my case. Commented Nov 18, 2019 at 12:13
  • 1
    Why? a powershell command can be run from a batch-file! Commented Nov 18, 2019 at 12:28

2 Answers 2

1

You can use <> as delims.

@for /f "tokens=2delims=><  " %%i in ('type pom.xml') dodo set "result=%%i" & goto :show
:show
echo %result%

or if you want a specific value only based on the property name of the tag..

@for /f "tokens=2delims=><  " %%i in ('type pom.xml ^| find /I "abc"') do set "result=%%i" & goto :show
:show
echo %result%
Sign up to request clarification or add additional context in comments.

7 Comments

I get the "abc" printed here not xyz. I want xyz as output
input should be the pattern which is <abc></abc> and whatever is between the pattern that should be the output. i.e., xyz.
No again the output is "abc". I guess the code is still the same.
The string has a tab. It will always be checkedout from SVN so the tab will be there always.
Yes working now.. There are multiple occurances now and I want only the first occurance. Can you please help with that as well?
|
0

you can try with xpath.bat:

call xpath.bat pom.xml "//abc"

to save it to a variable:

for /f "tokens=* delims=" %%# in ('xpath.bat pom.xml "//abc"') set "abc_value=%%#"
echo %abc_value%

1 Comment

@Sumith08 - to see how this will work you can download xpath.bat in the same directory as your script and test it...

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.