awk + print line only if the first field start with string as Linux1

awk ignores leading blanks when assigning fields. The default command is print.

awk '$1 ~ /^Linux1/'

Is what you want.

Detailed explanation:

  • $1 tells awk to look at the first "column".
  • ~ tells awk to do a RegularExpression match /..../ is a Regular expression.
  • Within the RE is the string Linux and the special character ^.
  • ^ causes the RE to match from the start (as opposed to matching anywhere in the line).

Seen together: Awk will match a regular expression with "Linux" at the start of the first column.


One way:

echo "Linux1_ver2  12542 kernel-update"  |  awk '$1 ~ /^ *Linux1/'

This should work for this specific case.

awk '/^[[:blank:]]*Linux1/ {print}'