This question already has an answer here:
- Difference between “cat” and “cat <” 4 answers
In very lot of answers, mainly about text-processing
commands, I saw commands such as sed
, awk
, grep
, among other, being used with STDIN and the simple open of a file
e.g.
$ sed -e 's|foo|bar|g' file # open file
$ sed -e 's|foo|bar|g' <file # open STDIN
or
$ grep 'PATTERN' file # open file
$ grep 'PATTERN' <file # open STDIN
In a personal, I use the open file method always, but I want to know when and when not to use them, also what's the difference.