如何使用sed在行后插入换行符/换行符 [英] How do I insert a newline/linebreak after a line using sed

查看:1398
本文介绍了如何使用sed在行后插入换行符/换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了一些时间弄清楚该怎么做,所以在其他人也要找同样的东西的情况下发布.

It took me a while to figure out how to do this, so posting in case anyone else is looking for the same.

推荐答案

要在模式后添加换行符,您还可以说:

For adding a newline after a pattern, you can also say:

sed '/pattern/{G;}' filename

引用 GNU sed手册:

G
    Append a newline to the contents of the pattern space, and then append the contents of the hold space to that of the pattern space.

顺便说一句,这恰好涵盖在固定一个衬里:

Incidentally, this happens to be covered in sed one liners:

 # insert a blank line below every line which matches "regex"
 sed '/regex/G'

这篇关于如何使用sed在行后插入换行符/换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆