O'Reilly logo

Learning AWK Programming by Shiwang Kalkhanda

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Modifying line spacing in a file with AWK

In this section, we look at various one-liners used for modifying the spacing between lines in a file, using AWK.

  • Double-space a file: In the following example, we first use the print statement with $0 to hold an entire line, followed by the second print statement to print nothing. In this, each print statement is followed by ORS, which prints a newline. Thus, each line gets double-spaced, as follows:
$ awk '{print $0 }{print ""}' label.dat

    Or:

$ awk '{print}{print ""}' label.dat

     Or:

$ awk '1{print}{print ""}' label.dat

    Or:

$ awk '1;{print ""}' label.dat

    Or:

$ awk '{print $0 "\n"}' label.dat

We can also double-space a file by setting the ORS variable value to 2 newlines instead ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required