Sed Regular Expressions: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
(Created page with "=Internal= * sed =Special Characters (need to be escaped in regular expressions)= <pre> / " $ # unescaped signifies end of line ! </pre> =Non-Spec...")
 
No edit summary
Line 21: Line 21:
     !
     !
     -
     -
</pre>
=Examples=
Match everything except space:
<pre>
    [^ ]*
</pre>
<pre>
    .*
</pre>
seems to work too.
Words (digits, alpha, _):
<pre>
sed -e 's/[0-9a-zA-Z_]*/THIS_WAS_A_WORD/g'
</pre>
Blank spaces (spaces, tabs, newlines):
<pre>
\s
</pre>
</pre>

Revision as of 16:40, 11 July 2016

Internal

Special Characters (need to be escaped in regular expressions)

     /
     "
     $ # unescaped signifies end of line 
     !

Non-Special Characters (do not need to be escaped in regular expressions)

     <
     >
     (
     )
     !
     -


Examples

Match everything except space:

     [^ ]*
     .*

seems to work too.

Words (digits, alpha, _):

sed -e 's/[0-9a-zA-Z_]*/THIS_WAS_A_WORD/g'

Blank spaces (spaces, tabs, newlines):

\s