Skip to content
Advertisement

How to cut string between two search patterns(including search patterns) from a file?

I have a file called applications.txt which contains the following data :

JavaScript

The strings in this file contain hostnames which I would like to display as follows :

JavaScript

Few of the above servers are UAT and few are PROD servers. As you see the host-names are sandwiched between two patterns:

  1. First pattern is -x (lowercase x only),
  2. Second pattern is either -UAT or -PRD. Whatever the string available in between first pattern and second pattern, we need to display.

note: From the first pattern x also should display in output. Example host name is: x01gmobdb2a

Advertisement

Answer

One using awk:

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