Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2013-06-13
3
Medium Priority
?
434 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 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

The purpose of this article is to demonstrate how we can use conditional statements using Python.
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
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 dynamically set the form action using jQuery.
Suggested Courses

886 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