Dinamo
Dinamo

Reputation: 61

matching string on the begining of the line with ash

I'm trying to match a string on the beginning of the line

a.z //match
# a.z
bc.x //match
 #bc.x
c.z
 bc.z //match

here is my code:

   while read p; do
      if [ $(expr match "$p" '^a\..*|^bc\..*') ];
      then
         echo $p
      fi
   done <file.txt

i get this error:

expr: warning: '^a..|^bc..: using '^' as the first character of a basic regular expression is not portable; it is ignored

What is the problem?

Upvotes: 1

Views: 157

Answers (1)

Gilles Qu&#233;not
Gilles Qu&#233;not

Reputation: 185560

What I would do, using awk:

awk '/^a\..*|^bc\..*/' file

expr is a program used in ancient shell code to do math. This syntax has been obsolete for a few decades.

Upvotes: 1

Related Questions