![Forrest logo](/images/logo.png)
awk:tldr:e6726
The command awk '/${foo}/ {print $2}' ${filename}
is using the awk
command-line tool to search for lines in ${filename}
(a file) that match the pattern set by the value of ${foo}
(a variable).
Let's break down the command:
-
${foo}
is a placeholder for a variable's value. In this case, it represents a pattern that will be matched. -
/.../
is used to delimit the pattern inawk
. So/${foo}/
means that the pattern is the value of${foo}
. -
{print $2}
is the action to be executed when a line matches the pattern.$2
refers to the second field (a column) of the matching line, andprint
is used to output that field. -
${filename}
represents the name of the file being processed byawk
.
So, in summary, the command searches ${filename}
for lines that contain the pattern ${foo}
and prints the second field of each matching line.