Solved

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

Posted on 2013-06-13
3
421 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
  • 2
3 Comments
 
LVL 31

Accepted Solution

by:
farzanj earned 500 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
This article will show, step by step, how to integrate R code into a R Sweave document
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

757 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now