Skip to content
Advertisement

How to get 2 strings between certain characters in bash

String:

JavaScript

I want to grab everything before the first instance of | and everything between External_SOC and ;PCRF. And store them as 2 different variables if possible.

JavaScript

This gives me the following:

JavaScript

40125512ALPHA3

Advertisement

Answer

EDIT: As per OP it needs to be done in a single line creation 2 of variables if this is the case then try following.

JavaScript

OR use following as per anubhav sir’s comment:

JavaScript


Could you please try following. One could use it from 2 separate commands to create 2 separate variables.

JavaScript
Advertisement