Skip to content
Advertisement

Search string in file via bash but only work match

Find the only string name based on the sub string name in a file.

Command used:

JavaScript

What works:

File content:

JavaScript

Output (desired output):

JavaScript

What does not work:

File content:

JavaScript

Output:

JavaScript

Need output SomeApi-CURRENT.war

Advertisement

Answer

It appears, you are interested in the docBase attribute of your xml elements. Specifically those where the value string contains “current” as a substring.

JavaScript

But this is a somewhat crude solution. Multiple assumptions have to be made in order to guarantee correctness.

As using grep etc. is not ideal, you would probably want to check xmllint which is a command line tool for parsing xml inputs. With XPath the command could look something like this:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement