views:

21

answers:

1

I'm trying to run the following:

  x=$(echo "$1" | egrep -c "^[0-9]|[:&^]")

Now, this code is supposed to look for a word that starts with a number, or contains a :,& or ^. However,I geta "no match" error when I run this in UNIX. What makes matters more cofusing is that something similar runs well in terminal, but not in a script.

A: 

try this

echo "$1" | nawk '{for(i=1;i<=NF;i++){ if($i ~/^[0-9]|[:&^]/ ){c++;}}}END{ print "count:"c}'
ghostdog74