I want to replace my pattern space in SED. I can do this with s/^.*$/hello world/;
- but can I do it using the c
command somehow - without using line breaks in my sed script? It's not entirely clear to me whether that's possible in any way.
(Same question for the a
and i
commands)
If your shell is bash, here is a convenient way to use
c
in a one-liner:This looks for any line containing
2
and changes it toNew Text
.This uses bash's
$'...'
feature to enter a newline in a string. The newline is represented by\n
. The backslash that is needed after thec
is represented by\\
.The
$'...'
feature is also available inksh93
,zsh
,mksh
, and FreeBSDsh
.