|
|
|
|
google site
|
|||||||
| Forums | Register | Blog | Man Pages | Forum Rules | Links | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|||
|
Need Help with Simple Regex
I have got a question. How to do this? I mean AND expression in regex.
List all the files in current directory that do not contain the words use AND take. Thx. ![]() |
| Sponsored Links | ||
|
|
|
|||
|
Assuming you want an answer rather than a theory, something like Code:
for f in *; do grep use "$f" >/dev/null && continue grep take "$f" >/dev/null && continue # file contains neither if we get to here; report its file name echo "$f" done If you really do require this to be done in regular expressions exclusively, there is no simple way to specify this in regular expressions. Theoretically there could be an operator & to parallel the operator | but in practice, it is fairly useless, and also complicates the regex engine a fair bit (if I recall the gist of the research papers on this topic correctly). |
|
|||
|
From the top of my head, I would use something like Code:
grep -L use $(grep -L take *.txt) which means, first (in the prenthesis) find all files that do not contain the word take, and in that list of files, find all the files that do not contain the word use. But I'm sure there is a way to use OR in the regexp.. /Lakris |
|
|||
|
Use egrep, search for $var1 OR $var2: Code:
egrep "[$var1]|[$var2]" file Invert match: Code:
egrep -v "[$var1]|[$var2]" file Search for $var1 AND $var2: Code:
egrep "$var1.*$var2|$var2.*$var1" file Invert match: Code:
egrep -v "$var1.*$var2|$var2.*$var1" file Regards Last edited by Franklin52; 08-31-2008 at 07:29 AM.. Reason: Adding invert match |
|
|||
|
Quote:
, I have to read the question thoroughly.Regards |
|
|||
|
useless use of cat?
I guess I misinterpreted the OP, now here is my supersilly superuseless use of cat and pipe... Code:
for x in *.txt;do cat $x|tr "\n" " "|egrep '(use.*take|take.*use)'&>/dev/null; [ $? == 1 ] && echo $x;done but I think it gets the job done? /Lakris |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Regex | pppswing | Shell Programming and Scripting | 5 | 06-30-2008 11:22 PM |
| A simple find and replace without using any regex (bash) | srikanths | Shell Programming and Scripting | 2 | 03-18-2008 08:08 AM |
| Regex | deepakpv | Shell Programming and Scripting | 6 | 03-28-2007 05:18 AM |
| Regex?? Please help | lunac | UNIX for Dummies Questions & Answers | 7 | 01-30-2007 01:13 PM |
| sed regex | Shakey21 | UNIX for Dummies Questions & Answers | 4 | 01-31-2002 09:16 PM |