Sponsored Content
Top Forums Shell Programming and Scripting Extract a string from another string in UNIX Post 302758923 by qwertyu on Monday 21st of January 2013 04:26:15 AM
Old 01-21-2013
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
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to extract a portion of a string from the whole string

How to extract a portion of a string from a full string using unix. For example: Say source string is = "req92374923.log" I want only the numeric portion of the string say "92374923" how to do that in Unix. (2 Replies)
Discussion started by: ds_sastry
2 Replies

2. Shell Programming and Scripting

Search for string in a file and extract another string to a variable

Hi, guys. I have one question: I need to search for a string in a file, and then extract another string from the file and assign it to a variable. For example: the contents of the file (group) is below: ... ftp:x:23: mail:x:34 ... testing:x:2001 sales:x:2002 development:x:2003 ...... (6 Replies)
Discussion started by: daikeyang
6 Replies

3. Shell Programming and Scripting

extract digits from a string in unix

Hi all, i have such string stored in a variable var1 = 00000120 i want the o/p var1 = 120 is it possible to have such o/p in ksh/bash ... thanx in advance for the help sonu (3 Replies)
Discussion started by: sonu_pal
3 Replies

4. Shell Programming and Scripting

to extract string from main string and string comparison

continuing from my previous post, whose link is given below as a reference https://www.unix.com/shell-programming-scripting/171076-shell-scripting.html#post302573569 consider there is create table commands in a file for eg: CREATE TABLE `Blahblahblah` ( `id` int(11) NOT NULL... (2 Replies)
Discussion started by: vivek d r
2 Replies

5. Shell Programming and Scripting

Extract a string between 2 ref string from a file

Hi, May i ask if someone share some command for extracting a string between 2 ref string in a txt file My objective: i had a file with multiple lines and wants only to extract the string "watch?v=IbkAXOmEHpY" or "watch?v=<11 random character>", when i used "grep 'watch?=*' i got a results per... (4 Replies)
Discussion started by: jao_madn
4 Replies

6. Shell Programming and Scripting

Extract First and matching word from string in UNIX

Thank you (2 Replies)
Discussion started by: Pratik Majithia
2 Replies

7. Shell Programming and Scripting

Search String and extract few lines under the searched string

Need Assistance in shell programming... I have a huge file which has multiple stations and i wanted to search particular station and extract few lines from it and the rest is not needed Bold letters are the stations . The whole file has multiple stations . Below example i wanted to search... (4 Replies)
Discussion started by: ajayram_arya
4 Replies

8. Shell Programming and Scripting

To Search for a string and to extract the string from the text

Hi Team I have an huge xml where i need to search for a ceratin numbers. For example 2014-05-06 15:15:41,498 INFO WebContainer : 10 CommonServicesLogs - CleansingTriggerService.invokeCleansingService Entered PUBSUB NOTIFY MESSAGE () - <?xml version="1.0" encoding="UTF-8"... (5 Replies)
Discussion started by: Kannannair
5 Replies

9. Shell Programming and Scripting

How to extract every repeated string between two specific string?

Hello guys, I have problem with hpux shell script. I have one big text file that contains like SOH bla bla bla bla bla bla ETX SOH bla bla bla ETX SOH bla bla bla ETX What I need to do is save first SOH*BLA into file1.txt, save second SOH*BLA into file2.txt and so on.... (17 Replies)
Discussion started by: sembii
17 Replies

10. Shell Programming and Scripting

How can I extract digits at the end of a string in UNIX shell scripting?

How can I extract digits at the end of a string in UNIX shell scripting or perl? cat file.txt abc_d123_4567.txt A246_B789.txt B123cc099.txt a123_B234-012.txt a13.txt What can I do here? Many thanks. cat file.txt | sed "s/.txt$//" | ........ 4567 789 099 012 13 (11 Replies)
Discussion started by: mingch
11 Replies
MB_EREG_REPLACE_CALLBACK(3)						 1					       MB_EREG_REPLACE_CALLBACK(3)

mb_ereg_replace_callback - Perform a regular expresssion seach and replace with multibyte support using a callback

SYNOPSIS
string mb_ereg_replace_callback (string $pattern, callable $callback, string $string, [string $option = "msr"]) DESCRIPTION
Scans $string for matches to $pattern, then replaces the matched text with the output of $callback function. The behavior of this function is almost identical to mb_ereg_replace(3), except for the fact that instead of $replacement parameter, one should specify a $callback. PARAMETERS
o $pattern - The regular expression pattern. Multibyte characters may be used in $pattern. o $callback - A callback that will be called and passed an array of matched elements in the $subject string. The callback should return the replacement string. You'll often need the $callback function for a mb_ereg_replace_callback(3) in just one place. In this case you can use an anonymous function to declare the callback within the call to mb_ereg_replace_callback(3). By doing it this way you have all information for the call in one place and do not clutter the function namespace with a callback function's name not used anywhere else. o $string - The string being checked. o $option - Matching condition can be set by $option parameter. If i is specified for this parameter, the case will be ignored. If x is specified, white space will be ignored. If m is specified, match will be executed in multiline mode and line break will be included in '.'. If p is specified, match will be executed in POSIX mode, line break will be considered as normal character. Note that e cannot be used for mb_ereg_replace_callback(3). RETURN VALUES
The resultant string on success, or FALSE on error. NOTES
Note The internal encoding or the character encoding specified by mb_regex_encoding(3) will be used as the character encoding for this function. EXAMPLES
Example #1 mb_ereg_replace_callback(3) example <?php // this text was used in 2002 // we want to get this up to date for 2003 $text = "April fools day is 04/01/2002 "; $text.= "Last christmas was 12/24/2001 "; // the callback function function next_year($matches) { // as usual: $matches[0] is the complete match // $matches[1] the match for the first subpattern // enclosed in '(...)' and so on return $matches[1].($matches[2]+1); } echo mb_ereg_replace_callback( "(d{2}/d{2}/)(d{4})", "next_year", $text); ?> The above example will output: April fools day is 04/01/2003 Last christmas was 12/24/2002 Example #2 mb_ereg_replace_callback(3) using anonymous function supported in PHP 5.3.0 or later <?php // this text was used in 2002 // we want to get this up to date for 2003 $text = "April fools day is 04/01/2002 "; $text.= "Last christmas was 12/24/2001 "; echo mb_ereg_replace_callback( "(d{2}/d{2}/)(d{4})", function ($matches) { return $matches[1].($matches[2]+1); }, $text); ?> SEE ALSO
mb_regex_encoding(3), mb_ereg_replace(3), Anonymous functions, information about the callback type. PHP Documentation Group MB_EREG_REPLACE_CALLBACK(3)
All times are GMT -4. The time now is 02:56 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy