i would like to know difference between below 2 commands, I understand that 2) should be use but i want to know the exact sequence that happens in 1) and 2) suppose filename
Functionally they are equivalent, however, the shell will fork two processes for cat filename | grep regex and connect them with a pipe.
cat filename | grep regex