I'm trying to show the list of all files which are not directories.I type ls -la | awk '$1 != d*'hoping that it won't show any strings in the first column that start with d but it doesn't work the way I've expected. Where is my mistake?
Trying to use awk to make ls show non-directories
awk;wildcards
!= is just a string comparison (or number comparison depending on what is being compared) operator. For string comparison (A != B), depending on the awk implementation, it's either a byte to byte comparison, or for some (as required by POSIX), it's short for A < B || A > B, that is A != B tests whether A and B sort differently.In any case, it is not a pattern matching operator. For that you have the ~ operator (negated with !~), though that's for regular expression matching, not wildcard pattern matching. You'd need:ls -la | awk '$1 !~ /^d/'Though here, you might as well use:ls -la | grep -v '^d'With $1 != d*, that would return true for anything except a first field that is (or sorts the same as with some awk implementaions) d*. d* as a regexp matches any number (including 0) of d, so $1 !~ d* would always return false as any string would contain at the very least 0 ds.