Reputation: 1
Using awk, I want to print all lines that have a string in the first column that starts with /dev/vda
I tried the following, but obviously *
does not work as a wildcard in awk:
awk '$1=="/dev/vda/*" {print $3}'
Is this possible in awk?
Upvotes: 0
Views: 765
Reputation:
For string matching there is the index()
function:
awk 'index($1, "/dev/vda") == 1'
The function returns the starting position of a substring, which must be 1 if it's at the beginning.
*
does not work as a wildcard
This is true – awk does not use shell-like patterns, although *
may appear as a regex metacharacter (where it would match zero or more repetitions of the the previous character).
Upvotes: 2
Reputation: 15247
awk '$1~/^\/dev\/vda\// {print $3}'
awk
has wildcards in regular expressions, not in string equality checks.
Technically the *
is not a wildcard in a regex, it's a quantifier. The regex equivalent of the wildcard *
of any number of any character would be .*
.
Upvotes: 1