Ask Ubuntu Asked by Tejas Kulkarni on January 3, 2022
I want to insert a new line after this line:
set_config_object("m_lin_1_pad_agent*","io_agent_config",m_lin_1_pad_agent_cfg,0);
Can you please guide me on how I can achieve that using the sed
command?
Brian Z's comment is a good suggestion. Indeed, using the a
command in sed
will append a string after the match.
However, if you directly use the string in your question as the matching string, you will find that nothing will happen. The problem is the *
character inside your string, which should be escaped, since sed
uses this character for regex match. In sed
you can escape a character by using a backslash () in front of it. You can find some more info about the characters that should be escaped in this U&L question.
So, the sed
command you need to run in order to append a string newstring
in a file called file.txt
after matching your string is (notice the escaped *
):
sed -i -e '/set_config_object("m_lin_1_pad_agent*","io_agent_config",m_lin_1_pad_agent_cfg,0);/ a newstring' file.txt
In the above command -i
is used to change the file in place. If you want to preview the changes first and ensure that the command works as it should, run the command without the -i
flag.
Answered by BeastOfCaerbannog on January 3, 2022
0 Asked on January 26, 2021 by john_connor
0 Asked on January 26, 2021 by ultranewbie
1 Asked on January 26, 2021 by user1725216
0 Asked on January 26, 2021
4 Asked on January 25, 2021 by rahul-raj-rai
2 Asked on January 25, 2021 by jorrit
1 Asked on January 24, 2021 by marievi
0 Asked on January 24, 2021 by arsh
0 Asked on January 24, 2021 by paul-wessex
1 Asked on January 24, 2021 by donttakemeseriously
0 Asked on January 23, 2021 by k-madhura-nadh-12a
4 Asked on January 23, 2021 by akaichi
0 Asked on January 23, 2021 by brad
0 Asked on January 23, 2021
0 Asked on January 23, 2021 by asocia
3 Asked on January 22, 2021 by thomas-ding
0 Asked on January 22, 2021 by salem-f
Get help from others!
Recent Answers
Recent Questions
© 2023 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP