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

Output field separator

The default value of the output field separator (OFS) is space. It is the output equivalent of the FS. We can set any string of characters to be used as the OFS by setting the predefined variable to OFS. The OFS is generated when we put a comma in the print statement to separate the arguments. For example, when we print the field without using a comma, then each of the field values are written contiguously in the output, as follows:

$ awk '{print NR"." $1 $3 $4}' emp.dat

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

1.Jack9857532312jack@gmail.com2.Jane9837432312jane@gmail.com3.Eva8827232115eva@gmail.com4.Amit9911887766amit@yahoo.com5.Julie8826234556julie@yahoo.com6.Ana9856422312anak@hotmail.com7.Hari8827255666hari@yahoo.com ...

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