Skip to content
TrySitePrice

Linux / Unix: Awk Print Variable

Best/Tutorial

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 myvarrn}

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.