Sponsored Content
Full Discussion: Regular expression with SED
Top Forums Shell Programming and Scripting Regular expression with SED Post 302387113 by Corona688 on Thursday 14th of January 2010 01:14:05 PM
Old 01-14-2010
Correct, it matches 0 or more charcters of that. The brackets surrounding it have a special meaning when you run sed with -r: it remembers that specific section in order to refer to it later. We match the entire string and keep the bit we want with brackets.

The .*$ lets the pattern match the entire string so it can replace the entire string. We want to delete everything after the hello, so we have to match it too.

Having matched the whole string, we keep the part we want as a backreference. \1 refers to the first section in brackets, \2 the second, and so forth. It needs the -r flag to work.

The last 'g' lets it match the pattern more than once if possible. Observe:
Code:
$ echo ababab | sed 's/a/b/'
bbabab
$ echo ababab | sed 's/a/b/g'
bbbbbb
$


Last edited by Corona688; 01-14-2010 at 02:20 PM..
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Regular expression with sed

Hi, I'm trying following:echo "test line XA24433 test" | sed 's/.*X\(.*\)/X\1/' XA24433 test While I want the output as: XA24433 I want to grab the words starting with letter X till the next space, this word can be anywhere in the line. (9 Replies)
Discussion started by: nervous
9 Replies

2. Shell Programming and Scripting

Regular expression (sed)

Hi I need to get text that are within "" For example File: asdasd "test test2" sadasds asdda asdasd "demo demo2" Output: test test2 demo demo2 Any help is good Thank you (12 Replies)
Discussion started by: blito_loco
12 Replies

3. Shell Programming and Scripting

sed regular expression help

please consider this: echo "11111*X*005010X279~ST*270*1111111*005010X279~BHT*0011*11" | sed 's/.*\(005010X(\d)(\d)(\d)*\).*$/\1/'i'm searching for first occurrence of 005010X while leaving rest of characters out. :confused: any tips? thnx in advance guys. (7 Replies)
Discussion started by: grep01
7 Replies

4. UNIX for Dummies Questions & Answers

Regular Expression In Sed

Hi , I am learing sed echo abc 123 def 456 | sed 's|\(*\) \(*\)|\1|' is returning abc def 456 i was hoping abc def "\1" should only print the occurence of the first pattern but according to my understanding it is just removing the first occurence of the second pattern... (7 Replies)
Discussion started by: max_hammer
7 Replies

5. Programming

Perl: How to read from a file, do regular expression and then replace the found regular expression

Hi all, How am I read a file, find the match regular expression and overwrite to the same files. open DESTINATION_FILE, "<tmptravl.dat" or die "tmptravl.dat"; open NEW_DESTINATION_FILE, ">new_tmptravl.dat" or die "new_tmptravl.dat"; while (<DESTINATION_FILE>) { # print... (1 Reply)
Discussion started by: jessy83
1 Replies

6. Shell Programming and Scripting

Help with sed regular expression

Hi all, I want to get a substring from a string based on given delimiter, for example: str="foo|bar|baz" with delimiter "|", I want to get one substring at each time with the order number the substring in the whole string, given 1 to get "foo", given 2 to get "bar", given 3 to get "baz", I... (2 Replies)
Discussion started by: Roy987
2 Replies

7. UNIX for Advanced & Expert Users

sed: -e expression #1, char 0: no previous regular expression

Hello All, I'm trying to extract the lines between two consecutive elements of an array from a file. My array looks like: problem_arr=(PRS111 PRS213 PRS234) j=0 while } ] do k=`expr $j + 1` sed -n "/${problem_arr}/,/${problem_arr}/p" problemid.txt ---some operation goes... (11 Replies)
Discussion started by: InduInduIndu
11 Replies

8. Shell Programming and Scripting

I am learning regular expression in sed,Please help me understand the use curly bracket in sed,

I am learning SED and just following the shell scripting book, i have trouble understanding the grep and sed statement, Question : 1 __________ /opt/oracle/work/antony>cat teledir.txt jai sharma 25853670 chanchal singhvi 9831545629 anil aggarwal 9830263298 shyam saksena 23217847 lalit... (7 Replies)
Discussion started by: Antony Ankrose
7 Replies

9. Shell Programming and Scripting

sed regular expression

Hi , I need to remove pipe character from a |^ delimeted file. Something like |^tran|sformers||^|revenge |of fallen|^ to |^transformers|^revenge of fallen|^... Cold anybody please help to build the regular expression using sed . many thanks. Please use code tags next time for... (1 Reply)
Discussion started by: kokjek
1 Replies
PPI::Token::Regexp(3)					User Contributed Perl Documentation				     PPI::Token::Regexp(3)

NAME
PPI::Token::Regexp - Regular expression abstract base class INHERITANCE
PPI::Token::Regexp isa PPI::Token isa PPI::Element DESCRIPTION
The "PPI::Token::Regexp" class is never instantiated, and simply provides a common abstract base class for the three regular expression classes. These being: m// - PPI::Token::Regexp::Match s/// - PPI::Token::Regexp::Substitute tr/// - PPI::Token::Regexp::Transliterate The names are hopefully obvious enough not to have to explain what each class is. See their pages for more details. To save some confusion, it's worth pointing out here that "qr//" is not a regular expression (which PPI takes to mean something that will actually examine or modify a string), but rather a quote-like operator that acts as a constructor for compiled Regexp objects. METHODS
The following methods are inherited by this class' offspring: get_match_string The "get_match_string" method returns the portion of the regexp that performs the match. get_substitute_string The "get_substitute_string" method returns the portion of the regexp that is substituted for the match, if any. If the regexp does not substitute, "undef" is returned. get_modifiers The "get_modifiers" method returns the modifiers of the regexp. get_delimiters The "get_delimiters" method returns the delimiters of the regexp as an array. The first element is the delimiters of the match string, and the second element (if any) is the delimiters of the substitute string (if any). SUPPORT
See the support section in the main module. AUTHOR
Adam Kennedy <adamk@cpan.org> COPYRIGHT
Copyright 2001 - 2011 Adam Kennedy. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of the license can be found in the LICENSE file included with this module. perl v5.16.2 2011-02-25 PPI::Token::Regexp(3)
All times are GMT -4. The time now is 05:04 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy