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?
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.