Re: [SLUG] multiple grep conditions ?
On 22 May 2014 14:12, li...@sbt.net.au wrote: On Wed, May 21, 2014 12:28 pm, pe...@chubb.wattle.id.au 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 Glad I did :) 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 Yes this will work. One pattern per line. See man grep. No need to quote or anything since it's not parsed through the shell. ? 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 -- [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
Re: [SLUG] multiple grep conditions ?
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
Re: [SLUG] multiple grep conditions ?
On Wed, May 21, 2014 12:28 pm, pe...@chubb.wattle.id.au 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
[SLUG] multiple grep conditions ?
I have a basic script that includes an exit on a date month condition, like so: /snip/ grep -q '07/2014' part2 exit 0 /snip/ I would like to add multiple additional non consecutive individual day date conditions, like say, 15/06/2014, 20/06, 25/06, like so; 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 I guess that would work OK, but, what's a good way to put all '06' entries in a single grep, egrep or how? thanks V -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
Re: [SLUG] multiple grep conditions ?
lists == lists li...@sbt.net.au writes: lists I have a basic script that includes an exit on a date month lists condition, like so: lists /snip/ grep -q '07/2014' part2 exit 0 /snip/ lists I would like to add multiple additional non consecutive lists individual day date conditions, like say, 15/06/2014, 20/06, lists 25/06, like so; lists grep -q '07/2014' part2 exit 0 grep -q '15/06/2014' lists part2 exit 0 grep -q '20/06/2014' part2 exit 0 grep -q lists '25/06/2014' part2 exit 0 lists I guess that would work OK, but, what's a good way to put all lists '06' entries in a single grep, egrep or how? 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 lists thanks lists V lists -- SLUG - Sydney Linux User's Group Mailing List - lists http://slug.org.au/ Subscription info and FAQs: lists http://slug.org.au/faq/mailinglists.html -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
Re: [SLUG] multiple grep conditions ?
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