The following pipeline gives the expected output:
( IFS=$'\n' ; echo "${pats[*]/#/^}" ) | grep -f- in.txt
The first part just outputs the patterns, each on its line and preceded by ^
. Grep then searches for the patterns, the ^
makes them match at the beginning of lines.
Update: The tag was changed to tcsh
. Ouch. This is a bash solution.