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

String concatenation

There is no specific operation to represent string concatenation. Space is a string concatenation operator that is used to merge two strings.

In the following example, we create three string variables to perform concatenation at different locations. In the statement, str3 contains the concatenated value of str1 and str2. Each print statement performs string concatenation with a static string value and AWK variable:

$ vi string.awkBEGIN    {    OFS=","    str1 = "Good"    str2 = "Morning"    num1 = "10"    str3 = str1 " " str2;    print "Concatenated string is : " str3    num1 = num1+1    print "string to number conversion on addition : " num1    }$ awk -f string.awk

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

Concatenated string ...

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