Solved

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

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
This article will show, step by step, how to integrate R code into a R Sweave document
The viewer will learn how to count occurrences of each item in an array.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

786 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