Mawk quantifier not working

92 Views Asked by At

I'm following an example in an awk book. I have the following bash script named "25regex.sh":

#!/usr/bin/env bash                                                      

# wh                                                                     
# wy                                                                     
# why                                                                    
# whhy                                                                   
# whhhy                                                                  
# whhhhy 

fname=25regex.sh                                                         

awk '/wh+y/ { print }' $fname                                            

echo                                                                     
awk '/wh{3}y/ { print }' $fname                                          

when I run the script it prints:

# why
# whhy
# whhhy
# whhhhy

awk '/wh{3}y/ { print }' $fname

I would expect the second awk command to print

# whhhy

So my question is, why is the second awk command being printed literally instead of being executed? Thanks.

The output of cat -A 25regex.sh is:

#!/usr/bin/env bash$
$
# wh$
# wy$
# why$
# whhy$
# whhhy$
# whhhhy$
$
fname=25regex.sh$
$
awk '/wh+y/ { print }' $fname$
$
echo$
# For some reason this is not working:$
awk '/wh{3}y/ { print }' $fname$
0

There are 0 best solutions below