The file i am working with (oraInst.loc) looks like this:
inventory_loc=/u01/app/ORAENV/orac开发者_如何学Pythonle/oraInventory
inst_group=dba
I need to use a regular expression to grab the value between app/ and /oracle. In this case it will be ORAENV but it could be any alphanumeric string of any case and length but with no spaces.
From what I have read so far using grouping seems to be the way to do this but I just can't get my head round it.
I am using egrep on Solaris 10 as the regex engine.
Try this:
\/app\/([\d\w]+)\/oracle\/
Try this, assuming your egrep has -o:
$ echo '/u01/app/ORAENV/oracle/oraInventory' | egrep -o '/app/[0-9A-Za-z]+/oracle/' | cut -d'/' -f3
Output:
ORAENV
Update, solution using sed:
$ echo '/u01/app/ORAENV/oracle/oraInventory' | sed 's:.*/app/\(.*\)/oracle/.*:\1:'
Something like:
app/(.*)/oracle
Would do the trick.
$ echo "inventory_loc=/u01/app/ORAENV/oracle/oraInventory"| nawk -F"/" '{for(i=1;i<=NF;i++)if($i=="app") {print $(i+1);exit} } '
ORAENV
精彩评论