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

Using each character as a separate field

If you want to print or examine each character of a line separately, then you can do this by defining a null string as an FS. In that case, each character in that line will become a separate field, as shown in the following example:

$ echo "hello good morning" |awk 'BEGIN {FS =""};{print $1,$2,$3,$4,$5,$NF}'

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

h e l l o g 

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