Solved

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

Posted on 2013-06-13
3
428 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 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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

630 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