0

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?

asaf92
  • 101
  • 2
  • 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 09:25

1 Answers1

1

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

You could use ==. Your command should be:

ls -la | awk '$9 == ".bashrc"'
Kamil Maciorowski
  • 69,815
  • 22
  • 136
  • 202
user1495523
  • 111
  • 1