tags:

views:

986

answers:

4

Probably easy to answer for you guys:

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

+8  A: 
smcameron
A: 
$ awk -v n=5 '$0=(!(NR%n))?"\n"$0:$0'

If you want to change 'n', please set the parameter 'n' by awk's -v option.

Hirofumi Saito
+1  A: 

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

awk 'NR % 5 == 0 {print ""} 1' myfile

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

glenn jackman
A: 

awk '{print; if (FNR % 5 == 0 ) printf "\n";}' your_file

I guess 'print' should be before 'printf', and FNR is more accurate for your task.

Joyer