The problem with this is it might be possible for the string MG to occur in another field, but the serial number indicate that it belongs to another department. What is necessary is a means of matching only a specific field. The modified awk program shown below searches field 4 for the string MG . Test the program, and after running the program successfully, enter the program in the space provided below. In all the previous examples, the output of the awk program has been either the entire line or fields within the line.
Lets add some text to make the output more meaningful.
We shall tidy the output information by using a built in function of awk called printf . C programmers will have no difficulty using this, as it operates the same way as in the C programming language. Printing A Text String Lets examine how to print out some simple text. Brackets are used to enclose the argument, and the text is enclosed using double quotes. Now lets combine it into an actual awk program which displays the location of all 286 type computers.