I have tried stuff like =~ "\[[A-Za-z0-9]+\]" which I would expect would work but doesnt. I also tried "[[A-Za-z0-9]+]" and "\[[:alnum:]+\]". What am I doing wrong? Sample line I want to match: [RTNUT18] (I am iterating through a file, some lines are of this form)
This is my code snippet:
while read line;
do
if [[ $line =~ "^\[[A-Za-z0-9]+\]$" ]]; then
echo match
else
echo no match
fi
done < $1
This is a sample file:
[RBPAT7]
Whatever=foo,bla
Otherline
RRR
and I run:
./script.sh thefile.txt
I am not getting a hit on the [RBPAT7] line at all
Stuff like that isn’t enough. You must use it in
[[.EDIT:
Unlike
test,[[does not need quotes around its arguments. Your code matches nothing, since you can’t have"before the beginning of the line, nor"after the end. Remove the quotes.