Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

Extract a string from another string in UNIX

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 01-21-2013
qwertyu qwertyu is offline
Registered User
 
Join Date: Nov 2012
Last Activity: 21 January 2013, 5:12 AM EST
Posts: 15
Thanks: 1
Thanked 0 Times in 0 Posts
Extract a string from another string in UNIX

I have a string

string="Please have a nice day and sleep well Replace_12123_31233_32134_12342 Good day"

How do i replace "Replace_12123_31233_32134_1234" in the above string.??

Please help.

Regards,
Qwerty
Sponsored Links
    #2  
Old Unix and Linux 01-21-2013
elixir_sinari's Unix or Linux Image
elixir_sinari elixir_sinari is offline Forum Advisor  
Registered User
 
Join Date: Mar 2012
Last Activity: 16 March 2015, 7:53 AM EDT
Location: India
Posts: 1,412
Thanks: 101
Thanked 496 Times in 473 Posts
bash/ksh93:

Code:
$ string="Please have a nice day and sleep well Replace_12123_31233_32134_12342 Good day"

$ string=${string//Replace_12123_31233_32134_12342/REPLACED}

$ echo $string
Please have a nice day and sleep well REPLACED Good day

Sponsored Links
    #3  
Old Unix and Linux 01-21-2013
qwertyu qwertyu is offline
Registered User
 
Join Date: Nov 2012
Last Activity: 21 January 2013, 5:12 AM EST
Posts: 15
Thanks: 1
Thanked 0 Times in 0 Posts
extract string from another string

i do not require to replace that with "Replaced". i want to take out that string - "Replace_12123_31233_32134_12342" and do certain operations with it... this might be a different string everytime... but the position of the string wouldnt change..
    #4  
Old Unix and Linux 01-21-2013
elixir_sinari's Unix or Linux Image
elixir_sinari elixir_sinari is offline Forum Advisor  
Registered User
 
Join Date: Mar 2012
Last Activity: 16 March 2015, 7:53 AM EDT
Location: India
Posts: 1,412
Thanks: 101
Thanked 496 Times in 473 Posts
Quote:
Originally Posted by qwertyu View Post
i do not require to replace that with "Replaced". i want to take out that string - "Replace_12123_31233_32134_12342" and do certain operations with it
Didn't you write "How do i replace "Replace_12123_31233_32134_1234" in the above string.??" earlier?

Quote:
Originally Posted by qwertyu View Post
... this might be a different string everytime... but the position of the string wouldnt change..
Please elaborate on this aspect. At what position will "this" string occur in the bigger string? Does "this" string terminate with a space/end-of-bigger-string? or does "this" string have a fixed length?
Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Unix or Linux Image More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Extract a string between 2 ref string from a file jao_madn Shell Programming and Scripting 4 05-15-2012 11:08 AM
to extract string from main string and string comparison vivek d r Shell Programming and Scripting 2 11-16-2011 07:17 AM
extract digits from a string in unix sonu_pal Shell Programming and Scripting 3 08-03-2010 05:30 AM
Search for string in a file and extract another string to a variable daikeyang Shell Programming and Scripting 6 03-20-2009 08:45 PM
extract a sub string from a main string madhu.it Shell Programming and Scripting 5 10-04-2008 02:22 AM



All times are GMT -4. The time now is 07:53 AM.