Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

korn shell - how to find the position of a string within a string

Posted on 2013-06-13
3
Medium Priority
?
431 Views
Last Modified: 2013-06-13
I have a string that I need to find and extract the "connect phrase" from it.

Here is an example string:

allocate channel c43 device type disk maxopenfiles 1 format '/u2/backup/TMKT/database/backup_%d_<static_date_seq>_%t%s%p' connect 'sys/<connect_pwd>@TMKT14';  

(that's one continuous string regardless of the formatting here)

What I need to do is:
1. find the position of "connect"
2. extract from the connect to the second single quote (')

The resulting extracted string in the example above would be:

connect 'sys/<connect_pwd>@TMKT14'

The catch is that I do not know where this occurs in the string because there are differing formats of the string, and the connect phrase itself is different between strings (in other words, it will not always be what is in the example above).

Any help is 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
3 Comments
 
LVL 31

Accepted Solution

by:
farzanj earned 2000 total points
ID: 39245544
This sed does what you are looking for basically


echo "allocate channel c43 device type disk maxopenfiles 1 format '/u2/backup/TMKT/database/backup_%d_<static_date_seq>_%t%s%p' connect 'sys/<connect_pwd>@TMKT14';   " | sed "s/.*\(connect .*'\)/\1/"
connect 'sys/<connect_pwd>@TMKT14';

Open in new window


You don't need to know where it is located as it would be counter productive although you can find it as well.
0
 
LVL 31

Expert Comment

by:farzanj
ID: 39245561
If the above doesn't satisfy your requirement, can you provide some more examples as to what you are looking for?
0
 

Author Closing Comment

by:dhite99
ID: 39245565
Perfect, thanks!
0

Featured Post

DFW AZURE MEETUP TONIGHT FRI 6PM

We will be discussing what Azure Stack is, how does it fit into the suit of offerings that Azure has currently, and where can it fit into your organizations technology stack. We will also be discussing limitations of the platform while covering various applicable scenarios.

Question has a verified solution.

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

Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

715 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