1

my file contains the Strings:

∗Cast and characters
* Bob Denver is Gilligan

I want to insert the line * ATTENTION * to any line starting with * followed by one OR more spaces. it will be preceded by a blank line and followed by a blank line inserted above it.
I have:

/^\*[ \t]/i\
\* ATTENTION \*

it gives me

∗Cast and characters
* ATTENTION *
* Bob Denver is Gilligan 

but I want :

∗Cast and characters 

∗ ATTENTION ∗

∗ Bob Denver is Gilligan

Note: I have BSD version of sed so i can't use \n

1 Answer 1

2

you were almost there. Just need to add escaped newlines in the inserted text.

/^\*[ \t]/i\
\
\* ATTENTION \*\

However, the idiomatic way of doing it, which is posixly, portable, nd avoids backslashing is:

/^[*][[:blank:]]/!b
H;s/.*//;x
s/./&** ACHTUNG **&&/
1
  • It is nice to see other ways to do it, but I would call the second option obscure at best. Even people used to Sed will stop to think there, while the first one is relatively clear. And the first one is also POSIX. Commented Sep 27, 2020 at 20:12

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.