J
J
juffinhalli2011-11-14 21:02:45
Regular Expressions
juffinhalli, 2011-11-14 21:02:45

[SOLVED] Linux sed regular expression splitting

Hello Habrazhitel!
Previously, sed always correctly processed multiple regular expressions separated by semicolon ";". This allowed us to run sed only once to process multiple regular expressions.
For example, comment on the lines containing "bugcode" and "betacode"
sed -i '/bugcode/s/^/\#/; /betacode/s/^/\#/' /etc/file
But today I found that this does not always work.
For example, you need to add the line "Ivan" after the line containing "123" and add the line "John" after the line containing "456".
sed -i '/123/a Ivan; /456/a John' /etc/file
As a result, the second regular expression is ignored and inserted as text.
Separately, regular expressions work correctly.
Please tell me where to dig, Google did not help.
Thank you in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
@
@sledopit, 2011-11-14
@juffinhalli

If I remember correctly, this is a feature of the a command (as well as i and c).
In order not to call sed a hundred times, you can do this:
echo -e "123\n456" | sed -e '/123/a Ivan' -e '/456/a John'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question