Linux / Unix: Awk Print Variable

In the awk programming language, you can use the print statement to output the value of a variable. For example:

#!/bin/awk -f

BEGIN {
# assign a value to a variable
myvar = "Hello, world!"

# print the value of the variable
print myvar
}

This script will print the string “Hello, world!” to the terminal.

You can also use the print statement to output the values of multiple variables, separated by commas:

#!/bin/awk -f

BEGIN {
# assign values to variables
myvar1 = "Hello"
myvar2 = "world!"

# print the values of the variables
print myvar1, myvar2
}

This script will print the string “Hello world!” to the terminal.

Leave a Comment