Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

Debian GNU/Linux Reference Guide
Prev Home Next

4.4.2 Replacement expressions

For the replacement expression, following characters have special meanings:

  • &

    • This represents what the regular expression matched. (use \& in emacs)

  • \n

    • This represents what the n-th bracketed regular expression matched.

For Perl replacement string, $n is used instead of \n and & has no special meaning.

For example:

     $ echo zzz1abc2efg3hij4 | \
       sed -e 's/\(1[a-z]*\)[0-9]*\(.*\)$/=&=/'
     zzz=1abc2efg3hij4=
     $ echo zzz1abc2efg3hij4 | \
       sed -e 's/\(1[a-z]*\)[0-9]*\(.*\)$/\2===\1/'
     zzzefg3hij4===1abc
     $ echo zzz1abc2efg3hij4 | \
       perl -pe 's/(1[a-z]*)[0-9]*(.*)$/$2===$1/'
     zzzefg3hij4===1abc
     $ echo zzz1abc2efg3hij4 | \
       perl -pe 's/(1[a-z]*)[0-9]*(.*)$/=&=/'
     zzz=&=

Here please pay extra attention to the style of the bracketed regular expression and how the matched strings are used in the text replacement process on different tools.

These regular expressions can be used for the cursor movements and the text replacement actions in the editors too.

Please read all the related manual pages to learn these commands.


Debian GNU/Linux Reference Guide
Prev Home Next

 
 
  Published under the terms of the GNU General Public License Design by Interspire