It might be more maintainable to keep the list of patterns in a variable
(line per pattern) then pass it to grep using grep's -f/--file= argument:

PATTERNS="15/06/2014
20/06/2014
25/06/2014"

...
grep -q -f <(echo "$PATTERNS") file2 && exit 0

Note the use of double quotes around the variable interpolation in the grep
command line, they are essential to preserve the newlines in the variable's
value.

The (bash specific, I think) trick here if the use of "<(command)" which
causes bash to open a pipe to the command and pass its name as
/dev/fd/FILE-DESC-NUMBER to grep so grep thinks it's a regular file to read
match patterns from while its stdin is still free to read the input to
match against the patterns. If grep doesn't read its input from stdin but
from a regular file then you don't need this trick and can just pass "-f -"
to make grep read the patterns from stdin and the matching text from the
regular file:

grep -q -f - file2 && exit 0 <<<"$PATTERNS"

(actually this uses another bash specific trick, you can do the following
to get rid of bash'ism completely:

echo "$PATTERN" | grep -q -f files && exit 0
)



On 21 May 2014 12:28, <li...@sbt.net.au> wrote:

>
> > grep -q '07/2014' part2 && exit 0 grep -q '15/06/2014' part2 && exit 0
> grep
> > -q '20/06/2014' part2 && exit 0
> > grep -q '25/06/2014' part2 && exit 0
>
> is this the way to do this ?
>
> grep -q -e '15/06/2014' -e '20/06/2014' -e '25/06/2014' file2 && exit 0
>
>
>
> --
> SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
> Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
>



-- 
 [image: View my profile on LinkedIn]
<http://www.linkedin.com/in/gliderflyer>
-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html

Reply via email to