The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #4 (permalink)  
Old 09-27-2006
Corona688 Corona688 is offline
Registered User
  
 

Join Date: Aug 2005
Location: Saskatchewan
Posts: 1,933
You might want to use the '-r' option to tell sed to use extended regular expressions. Basic sed regexes are quite limited.

Second, regular expressions work differently in sed than they do in a shell. * doesn't mean anything by itself, it's a modifier for something else. First you tell it what expression you want to match, then optionally, how many of them you want to match. An expression can be a single letter, a set of letters, or something in brackets.
  • A by itself just matches the letter A, like you'd expect.
  • [ABC] by itself just matches the letter A, B, or C.
  • A* tells it to match 0 or more A characters.
  • [ABC]* tells it to match 0 or more characters among A, B, C.
  • [A-Z]* tells it to match 0 or more characters among A, B, C, ..., Z.
  • [^A]* tells it to match 0 or more characters that aren't A.
  • (ABC)* tells it to match 0 or more repititions of "ABC".

* is not the only modifier:
  • A+ tells it to match 1 or more A characters.
  • A? tells it to match 0 or 1 A characters.
  • A{4} tells it to match precisely 4 A characters.