grep and grep -f differences
You're using grep with basic regular expressions. grep ^aaa\| file.txt
is the same as typing grep "^aaa|" file.txt
. While reading the file grep -f regex.txt file.txt
is the same as grep "^aaa\|" file.txt
., the escaped |
means match ^aaa
or ""
which matches anything.