On Wed, May 21, 2014 12:28 pm, [email protected] wrote: > As you're not using regular expressions, but just strings, fgrep is > the way to do it. fgrep -q '07/2014 15/06/2014 > 20/06/2014 > 25/06/2014' part 2 && exit 0
Peter, thanks Amos, you've per-emptied my next Q, thanks I actually should move it totally out of script, as this list will often change, so (I think?) I can enter dates into a file, say 'patterns' and, use like fgrep -q -f /path/to/pattern part2 && exit 0 ? will I need any quotes in file 'pattern', or simply like: 07/2014 15/06/2014 20/06/2014 25/06/2014 thanks again V On Wed, May 21, 2014 7:24 pm, Amos Shapira wrote: > 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 ) -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
