8

[sed] Insert Line After First Pattern Match

 3 years ago
source link: http://siongui.github.io/2016/03/20/sed-insert-line-after-first-pattern-match/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

[sed] Insert Line After First Pattern Match

March 20, 2016

Insert a line after first pattern match via sed stream editor.

In the files with names starting with dhp-story under current directory, find the line that starts with :oldurl:, insert the following line after the matched line:

:author: 護法法師

sed -i '/:oldurl:/a :author: 護法法師' dhp-story*

Tested on Ubuntu Linux 15.10, sed 4.2.2-6.1.

References:

[2][Python] Insert Line With Matched Pattern


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK