How to extract a variable length substring using ksh How to extract a variable length substring using ksh shell shell

How to extract a variable length substring using ksh


With pure bash's parameter expansion capability.

var="SID_LIST_ORADBPOC1LSN ="  ##Creating shell variable here.temp1="${var##*_}"             ##Removing everything till _ ## for longest match here.echo "${temp1/ =/}"            ##Substituting space = with null here.ORADBPOC1LSN

I am printing value of temp1's parameter expansion, you could save this into variable too as per your need.



OR if you want to do it in a single awk or so then try:

echo "$var" | awk -F'_| ' '{print $3}'