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
If you want to check the actual execution time diffrence, first create a file with 100000 lines:
user@server ~ $ for i in $(seq 1 100000); do echo line${1} >> test_f; done
user@server ~ $ wc -l test_f
100000 test_f
Now measure:
user@server ~ $ time grep line test_f
#...
real 0m1.320s
user 0m0.101s
sys 0m0.122s
user@server ~ $ time cat test_f | grep line
#...
real 0m1.288s
user 0m0.132s
sys 0m0.108s
As we can see, the diffrence is not too big...