?
Solved

Korn Shell - How to Find A String within a String

Posted on 2013-06-05
2
Medium Priority
?
401 Views
Last Modified: 2013-06-05
Let's say a variable contains this string:
testvar="allocate channel c1 device type disk rate 20M maxopenfiles 1 format '/u900/backup/<oracle_sid>/database/backup_%d_<static_date_seq>_%t%s%p';"

Open in new window

What I need to do is:
1. preserve everything up to the word disk, then replace the word disk with 'SBT_TAPE'
2. preserve everything after the word disk up until the word "format"
3. create a new string that, considering the testvar contents above, would look like the following:
allocate channel c1 device type 'SBT_TAPE' rate 20M maxopenfiles 1  PARMS 'BLKSIZE=1048576, SBT_LIBRARY=<oracle_home>/lib/libddobk.so, ENV=(STORAGE_UNIT=emergo,BACKUP_HOST=USTSSSNSBRE024.sabre.com,ORACLE_HOME=<oracle_home>)' format 'df_%d_%I_<static_date_seq>_%U_%t%s%p';

Open in new window


Do not be concerned with the string beginning with PARMS, I can supply that no problem. The real objectives are items 1 and 2 - extract into a variable all up until the word 'disk' and then extract into another variable all after the word 'disk' and before the word 'format'.

Unfortunately I cannot just create a new line from scratch because there are thousands of these that will have to be converted and there are different options being used in the statement.

Any help will be much appreciated - thanks!
0
Comment
Question by:dhite99
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 2000 total points
ID: 39223084
I don't know if I really understand....

1. extract into a variable all up until the word 'disk', replace 'disk' with 'SBT_TAPE':

VAR1=$(echo $testvar | sed "s/\(^.*\)disk.*/\1SBT_TAPE/")

echo $VAR1

2. extract into another variable all after the word 'disk' and before the word 'format'.

VAR2=$(echo $testvar |sed "s/.*disk\(.*\)format.*/\1/")

echo $VAR2


... or for VAR2 rather this:

VAR2=$(echo $testvar |sed "s@.*disk\(.*\)format.*@\1PARMS 'BLKSIZE=1048576, SBT_LIBRARY=<oracle_home>/lib/libddobk.so, ENV=(STORAGE_UNIT=emergo,BACKUP_HOST=USTSSSNSBRE024.sabre.com,ORACLE_HOME=<oracle_home>)'@")

echo $VAR2

Open in new window

0
 

Author Closing Comment

by:dhite99
ID: 39223132
woolmilkporc you always come through with the great answers! Thanks!!!
0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
This article will show, step by step, how to integrate R code into a R Sweave document
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question