我要如何插入一个空行每n行用awk? [英] How do I insert a blank line every n lines using awk?

查看:366
本文介绍了我要如何插入一个空行每n行用awk?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个输入文件是这样的:

I've got an input file like this:

line 1
line 2
line 3
line 4
line 5
line 6

我想用awk插入一个空行每隔几行;例如,每两个

I'd like to use awk to insert a blank line every few lines; for example, every two:

line 1
line 2

line 3
line 4

line 5
line 6

如何才能AWK把一个空行到我的文件中的每个n行?

How can I get awk to put a blank line into my file every n lines?

推荐答案

一个更AWK-ISH的方式来写smcameron的回答是:

A more "awk-ish" way to write smcameron's answer:

awk -v n=5 '1; NR % n == 0 {print ""}'

在1;是永远满足的条件,并且会触发默认操作是打印当前行。

The "1;" is a condition that is always true, and will trigger the default action which is to print the current line.

这篇关于我要如何插入一个空行每n行用awk?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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