LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-06-2006, 02:13 AM   #1
zzytech
LQ Newbie
 
Registered: Apr 2006
Posts: 3

Rep: Reputation: 0
Command about AND / OR / NOT, help!


There are only 3 files in same directory like this:

file1
------
aaa
xxx

file2
-------
bbb
xxx

file3
-----
aaa
bbb
xxx
Two question are:

Q1. List all the files that do not contain the words 'aaa' AND 'bbb'.

Q2. List all the files that do not contain the words 'aaa' OR 'bbb'.

=============================================
For the first one, my answer is:

grep -Lw 'aaa' * | xargs -i grep -Lw 'bbb' {}

Is this correct or not?

For the second one, is that a equal one like "all the files do not contain word 'aaa' OR do not contain word 'bbb'"? If so, I think file1 and file2 should both match with follow command:

grep -ELw 'aaa|bbb' *

But after check that, I found nothing match, Why? If they are not equal question, how to work out the answer?

Anyone can help? Thanks a million!

Last edited by zzytech; 04-06-2006 at 02:15 AM.
 
Old 04-06-2006, 05:58 AM   #2
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
In my opinion, and this does sound like homework to me, Q1 should have files 1 & 2 as answer, whereas Q2 should have all of the files as answer.
OR is not the same as XOR (exclusive OR).

In standard logic, the operations AND, OR and XOR are defined as follows:

c1 - c2 - c1 AND c2 - c1 OR c2 - c1 XOR c2
F - F - F - F - F
T - F - F - T - T
F - T - F - T - T
T - T - T - T - F

So, in short, "AND" yields "T" (true) if both conditions (c1 and c2) are met at the same time.
"OR" yields true if either or both of the conditions is true.
"XOR" yields true if either of the conditions is true, but not both.

Since Q2 asks for "OR", not "XOR", all three files have either "aaa" or "bbb" (or both) in them.

As your command for Q2 yielded none of the three files, I suspect your command is wrong.
And indeed: you are asking grep to match either "aaa" or "bbb". If either is found in the file, the file is considered as "file with match". -L only shows the files that don't match.
So, replace -L with -l and you should get all the files that match "aaa" or "bbb".
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there a single command to list all hardware installed (command line)? davee Linux - Hardware 6 02-28-2009 08:19 PM
Require Linux/Perl equivalent command for windows Command alix123 Programming 7 08-19-2005 03:23 AM
Why after start of a command the invitation for input next command has not appeared. ukrainet Linux - General 3 06-24-2005 09:16 AM
Key stroke/command to shut down x and go into the command prompt screen? Fear58 Linux - General 1 07-14-2004 08:14 PM
Where is Command line utility for Cups and command tutorial mossy Linux - Software 8 01-16-2004 01:24 AM


All times are GMT -5. The time now is 12:34 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration