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

Outputting the record separator

The default value of the output record separator (ORSis a single newline by default. We assign new values to the variable ORS to change how records are separated. It is also used to create a formatted output. Let us say that we want to print each line separated by a sequence of special character asterisks, as follows:

$ vi  ors.awk #!/usr/bin/awk -fBEGIN { ORS="\n**************************************************************\n"}{ print $0 }$ awk -f ors.awk emp.dat

The output of the execution of the preceding code is as follows:

Jack    Singh   9857532312  jack@gmail.com      M   hr      2000****************************************************************Jane    Kaur    9837432312  jane@gmail.com      F   hr      1800**************************************************************** ...

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