I'm trying to match the string in specific position using substr an running it in a loop
For example my cardfile.txt contains
01
02
My input file is
02AAA45678
04BBB04673
01CCC63848
05DDD07494
I want in the output lines having either 01 or 02 in the first 2 characters as below
02AAA45678
01CCC63848
for i in `cat cardfile.txt`
do
awk 'substr($0,1,2) == $i {print} ' input.txt > output.txt
done
If I'm trying to run by giving the string in substr directly like "02" it is working properly but if I am giving $i it is not matching the string
Thanks in advance