Using this question I've tried to match whole words with awk.

In my homerdir there's a file called .bashrc, but when I try to use:

ls -la | awk '$9 ~ /\<.bashrc\>/'

It doesn't show anything.

Also tried:

ls -la | awk '{if($9 ~ "^.bashrc" && $9 ~ "$.bashrc") echo $0}'

Still doesn't work.

What am I doing wrong?

  • 1
    What is the expected output? From your question I don't see any reason to not simply use ls .bashrc or find . -name ".bashrc" – Argonauts Aug 25 '16 at 16:30
  • Assuming this is actually part of a larger problem (otherwise, I completely agree with Argonauts' suggestion), that regex syntax \< is supported by GNU awk (are you using another version?). Stupid suggestion maybe, but could you post the output of ls -la ? – Edward Aug 26 '16 at 9:25

~ is used for string comparison, it is not for exact match.

You could use ==. Your command should be:

ls -la | awk '$9 == ".bashrc"'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.