Extract a string from another string in UNIX | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Extract a string from another string in UNIX

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 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 01-21-2013
elixir_sinari's Avatar
elixir_sinari elixir_sinari is offline Forum Advisor  
Gotham Knight
 
Join Date: Mar 2012
Last Activity: 16 July 2014, 3:22 PM EDT
Location: India
Posts: 1,412
Thanks: 100
Thanked 495 Times in 472 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 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 01-21-2013
elixir_sinari's Avatar
elixir_sinari elixir_sinari is offline Forum Advisor  
Gotham Knight
 
Join Date: Mar 2012
Last Activity: 16 July 2014, 3:22 PM EDT
Location: India
Posts: 1,412
Thanks: 100
Thanked 495 Times in 472 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 Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 11:39 PM.