P
P
patashnik2012-04-24 17:44:45
Command line
patashnik, 2012-04-24 17:44:45

How to insert text between lines using sed?

It is necessary to insert a part of the text between lines containing certain substrings (or falling under a regular expression).

Answer the question

In order to leave comments, you need to log in

2 answer(s)
@
@sledopit, 2012-04-24
_

Well, now the question makes more sense. The clarification problem is solved as follows:

echo -e "aaa\nbbb\naaa\nddd" | sed '/aaa/{n;/bbb/i new_line
}'

@
@sledopit, 2012-04-24
_

It is not entirely clear what it means between the lines. But anyway:
a. if you need to insert after the line with the template:

echo -e "1\n2\n3\n4" | sed '/2/a test'

if you need to insert after each line between the start and end according to the pattern:
echo -e "1\n2\n3\n4" | sed '/2/,/4/a test'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question