Sed: Difference between revisions

From DWIKI
Tony (talk | contribs)
Tony (talk | contribs)
 
(9 intermediate revisions by the same user not shown)
Line 6: Line 6:
=Tutorials=
=Tutorials=
*[http://www.grymoire.com/Unix/Sed.html Sed - An Introduction and Tutorial by Bruce Barnett]
*[http://www.grymoire.com/Unix/Sed.html Sed - An Introduction and Tutorial by Bruce Barnett]
=HOWTO=
==Back references without escaping parenthesis==
sed 's/foo (bar)/\1/g'


=FAQ=
==+ or *==
===*===
matches 0 or more
===+===
matches 1 or more
==errror messages==
===sed: -e expression #1, char 32: unknown command: `\'===
try
's/...
instead of
'/...
==Replace with newline==
^V^M
==Replace literal \n with actual newline==
sed 's/\\n/\n/g'


=FAQ=
==match whitespace==
==match whitespace==
  \s
  \s
Line 15: Line 34:
try tr instead:
try tr instead:
  tr -d '\n' < file
  tr -d '\n' < file
==Edit in-place==
sed -i
==match number==
sed 's/.*\([0-9]\+\).*/\1/'
or
sed -r 's/.*([0-9]+).*/\1/'
==Split words==
sed -r 's/([^ ]+) +([^ ]+) +([^ ]+) +([^ ]+) +([^ ]+) +([^ ]+) +([^ ]+).*/\4/g'

Latest revision as of 09:58, 26 May 2026

Stream Editor

Links

Tutorials

HOWTO

Back references without escaping parenthesis

sed 's/foo (bar)/\1/g'

FAQ

+ or *

*

matches 0 or more

+

matches 1 or more

errror messages

sed: -e expression #1, char 32: unknown command: `\'

try

's/...

instead of

'/...

Replace with newline

^V^M

Replace literal \n with actual newline

sed 's/\\n/\n/g'

match whitespace

\s

replace newline

try tr instead:

tr -d '\n' < file


Edit in-place

sed -i


match number

sed 's/.*\([0-9]\+\).*/\1/'

or

sed -r 's/.*([0-9]+).*/\1/'

Split words

sed -r 's/([^ ]+) +([^ ]+) +([^ ]+) +([^ ]+) +([^ ]+) +([^ ]+) +([^ ]+).*/\4/g'