It was an exercise from one Linux textbook: to give an example both input and output redirected. I found an answer in web:
grep \$Id < *.c > id_listBut this *.c seems to be the problem. Can this answer be worked around?
32 Answers
Since grep can read from files whose names are passed to it as arguments, you don't need input redirection at all here:
grep '$Id' -- *.c > id_listBy default, if *.c expands to a list of more than one file, then grep will prefix each match output with the filename in which it was found; if you don't want that, add the -h (or --no-filename) switch.
For a recursive search, you can make use of the --include option
grep -r --include='*.c' '$Id' . > id_list It's not possible to redirect more than of one file to input using <. ( or even output, for output you should use tee).
To demonstrate a working example, you can use something like: grep \$Id < 1.c > id_list.
You can also use "here string" type of redirection to get you want.
grep <<< $(cat *.c) > out 2