|
Mailing Lists
|
Home /
Groups /
Regular Expressions (RegEx)
OT Regex question
Assuming this list is still alive, looks like the last post was from February.Ian Skinner 10/05/10 04:15 P It certainly does matter that it's Unix grep, because that allows youPeter Boughton 10/05/10 04:55 P >To put the two commands together, you chain them with a pipe character, like so:Ian Skinner 10/07/10 10:03 A Assuming this list is still alive, looks like the last post was from February. Can somebody suggest a regex expression that would find all lines that contains an arbitrary string only if it DOES NOT contain another arbitrary string. I.E. find all lines that contain the word master only if it does not contain the word California, case insensitive. Assuming it matters, this would be for use in a Unix grep command to search a large CFML code base. It certainly does matter that it's Unix grep, because that allows you to pipe and invert, which is far easier and probably faster too. To get everything that contains 'master' you'd do: grep -ir 'master' ./* And to get get everything that does NOT contain 'california' you use: grep -irv 'california' ./* Where: -i means case-Insensitive -r means Recursively scan directories. -v means inVerted (negative search) and -ir or -irv combined does both/all of those. The ./* is the files to search (i.e. everything in the current directory - and, due to the -r flag, everything in any sub-directories too). To put the two commands together, you chain them with a pipe character, like so: grep -ir 'master' ./* | grep -iv 'california' For the second command here, you don't need the ./* part because it accepts the list of files that matched the first command as its input. Hopefully that all makes sense? >To put the two commands together, you chain them with a pipe character, like so: > > grep -ir 'master' ./* | grep -iv 'california' > >Hopefully that all makes sense? Thanks for the answer, back to work after a day off yesterday. So I now get to try and implement your suggestion into the Solaris system we use which does not have the recursive option for grep. This is what I have been using to search for a single string so I presume I just need to add the grep -iv command to this, but I'm not sure how.
|
May 23, 2013
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||