how can I find all lines containing two words?
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I need to check if two words are exist on any line in a text file. there are no limits for the characters of the words For example:
I want to find lines of a text that contain the two words cat and elephant together:
Cat is smaller than elephant
Elephant is larger than ca
Cats are cute!
Elephants are very strong
Cat and elephants live in different environment
cats are friendly
In the previous examples, how can I find the lines containing both words
Cat is smaller than elephant
Elephant is larger than cat
Cat and elephants live in different environment
I tried grep and awk with no hope, the problem is there are words have upper and lower case so how can I match for both words regardless of its letter status!?
thanks for any help
bash
New contributor
add a comment |Â
up vote
0
down vote
favorite
I need to check if two words are exist on any line in a text file. there are no limits for the characters of the words For example:
I want to find lines of a text that contain the two words cat and elephant together:
Cat is smaller than elephant
Elephant is larger than ca
Cats are cute!
Elephants are very strong
Cat and elephants live in different environment
cats are friendly
In the previous examples, how can I find the lines containing both words
Cat is smaller than elephant
Elephant is larger than cat
Cat and elephants live in different environment
I tried grep and awk with no hope, the problem is there are words have upper and lower case so how can I match for both words regardless of its letter status!?
thanks for any help
bash
New contributor
Try withgrep
again, but usegrep -i
. This makes its matching disregard the case of the letters. Also, please show what you've tried so that other's make comment and give suggestions for improvement. For example, does your command distinguish that "catnip" is not the word "cat"?
â Kusalananda
8 secs ago
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I need to check if two words are exist on any line in a text file. there are no limits for the characters of the words For example:
I want to find lines of a text that contain the two words cat and elephant together:
Cat is smaller than elephant
Elephant is larger than ca
Cats are cute!
Elephants are very strong
Cat and elephants live in different environment
cats are friendly
In the previous examples, how can I find the lines containing both words
Cat is smaller than elephant
Elephant is larger than cat
Cat and elephants live in different environment
I tried grep and awk with no hope, the problem is there are words have upper and lower case so how can I match for both words regardless of its letter status!?
thanks for any help
bash
New contributor
I need to check if two words are exist on any line in a text file. there are no limits for the characters of the words For example:
I want to find lines of a text that contain the two words cat and elephant together:
Cat is smaller than elephant
Elephant is larger than ca
Cats are cute!
Elephants are very strong
Cat and elephants live in different environment
cats are friendly
In the previous examples, how can I find the lines containing both words
Cat is smaller than elephant
Elephant is larger than cat
Cat and elephants live in different environment
I tried grep and awk with no hope, the problem is there are words have upper and lower case so how can I match for both words regardless of its letter status!?
thanks for any help
bash
bash
New contributor
New contributor
New contributor
asked 8 mins ago
gormet
1
1
New contributor
New contributor
Try withgrep
again, but usegrep -i
. This makes its matching disregard the case of the letters. Also, please show what you've tried so that other's make comment and give suggestions for improvement. For example, does your command distinguish that "catnip" is not the word "cat"?
â Kusalananda
8 secs ago
add a comment |Â
Try withgrep
again, but usegrep -i
. This makes its matching disregard the case of the letters. Also, please show what you've tried so that other's make comment and give suggestions for improvement. For example, does your command distinguish that "catnip" is not the word "cat"?
â Kusalananda
8 secs ago
Try with
grep
again, but use grep -i
. This makes its matching disregard the case of the letters. Also, please show what you've tried so that other's make comment and give suggestions for improvement. For example, does your command distinguish that "catnip" is not the word "cat"?â Kusalananda
8 secs ago
Try with
grep
again, but use grep -i
. This makes its matching disregard the case of the letters. Also, please show what you've tried so that other's make comment and give suggestions for improvement. For example, does your command distinguish that "catnip" is not the word "cat"?â Kusalananda
8 secs ago
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
0
down vote
grep -i "cat" file | grep -i "elephant"
Cat is smaller than elephant
Elephant is larger than cat
Cat and elephants live in different environment
The flag in grep
is to ignore case (upper/lower)
-i, --ignore-case ignore case distinctions
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
grep -i "cat" file | grep -i "elephant"
Cat is smaller than elephant
Elephant is larger than cat
Cat and elephants live in different environment
The flag in grep
is to ignore case (upper/lower)
-i, --ignore-case ignore case distinctions
add a comment |Â
up vote
0
down vote
grep -i "cat" file | grep -i "elephant"
Cat is smaller than elephant
Elephant is larger than cat
Cat and elephants live in different environment
The flag in grep
is to ignore case (upper/lower)
-i, --ignore-case ignore case distinctions
add a comment |Â
up vote
0
down vote
up vote
0
down vote
grep -i "cat" file | grep -i "elephant"
Cat is smaller than elephant
Elephant is larger than cat
Cat and elephants live in different environment
The flag in grep
is to ignore case (upper/lower)
-i, --ignore-case ignore case distinctions
grep -i "cat" file | grep -i "elephant"
Cat is smaller than elephant
Elephant is larger than cat
Cat and elephants live in different environment
The flag in grep
is to ignore case (upper/lower)
-i, --ignore-case ignore case distinctions
answered 44 secs ago
Goro
9,62364689
9,62364689
add a comment |Â
add a comment |Â
gormet is a new contributor. Be nice, and check out our Code of Conduct.
gormet is a new contributor. Be nice, and check out our Code of Conduct.
gormet is a new contributor. Be nice, and check out our Code of Conduct.
gormet is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f475908%2fhow-can-i-find-all-lines-containing-two-words%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Try with
grep
again, but usegrep -i
. This makes its matching disregard the case of the letters. Also, please show what you've tried so that other's make comment and give suggestions for improvement. For example, does your command distinguish that "catnip" is not the word "cat"?â Kusalananda
8 secs ago