[SOLVED] grep -f pattern.txt file.txt omit extraneous information
by crusader7 from LinuxQuestions.org on (#5CYA5)
Hey guys,
I only want the lines to print that contain my pattern using the grep command. Instead it prints the entire file and just highlights the patterns that I am looking for.
I have two files: pattern.txt contains all of the patterns that I want to search for in the file.txt.
I used the command:
grep -f pattern.txt file.txt
My sample pattern.txt contains the following patterns:
Quote:
My sample file.txt contains the following lyrics from the movie Mary Poppins:
Quote:
So when I try grep -f pattern.txt file.txt, it prints the entire file and highlights the patterns that I am searching for. How do I get it to only print the lines that have the patterns that I am looking for? I have done multiple google searches, but I have not had a satisfactory answer. Any suggestions would be greatly appreciated.
If I use the command, grep -o -f pattern.txt file.txt it only prints the patterns that are found in the file.txt and does not print the entire line.
If I use the command grep -w -f pattern.txt file.txt it There are still lines that show up that do not contain the patterns.


I only want the lines to print that contain my pattern using the grep command. Instead it prints the entire file and just highlights the patterns that I am looking for.
I have two files: pattern.txt contains all of the patterns that I want to search for in the file.txt.
I used the command:
grep -f pattern.txt file.txt
My sample pattern.txt contains the following patterns:
Quote:
the nose jim cat was Supercalifragilisticexpialidocious |
Quote:
It's supercalifragilisticexpialidocious Even though the sound of it is something quite atrocious If you say it loud enough, you'll always sound precocious Supercalifragilisticexpialidocious Um diddle diddle, diddle um, diddle ay x4 Because I was afraid to speak When I was just a lad Me father gave me nose a tweak And told me I was bad But then one day I learned a word That saved me achin' nose The biggest word you ever heard And this is how it goes, oh Supercalifragilisticexpialidocious Even though the sound of it is something quite atrocious If you say it loud enough, you'll always sound precocious Supercalifragilisticexpialidocious Um diddle diddle, diddle um, diddle ay x4 He traveled all around the world And everywhere he went He'd use his word and all would say There goes a clever gent When Dukes and Maharajahs Pass the time of day with me I say me special word And then they ask me out to tea Oh! Supercalifragilisticexpialidocious Even though the sound of it is something quite atrocious If you say it loud enough, you'll always sound precocious Supercalifragilisticexpialidocious Um diddle diddle, diddle um, diddle ay x2 ? Now, you can say it backwards, which is docious-ali-expi-listic-fragi-cali-rupus But that's going a bit too far, don't you think? So when the cat has got your tongue There's no need for dismay Just summon up this word And then you've got a lot to say But better use it carefully Or it could change your life For example? ?Yes?? One night I said it to me girl And now me girl's my wife <clash> Oh, and a lovely thing she's too She's, supercalifragilisticexpialidocious Supercalifragilisticexpialidocious Supercalifragilisticexpialidocious Supercalifragilisticexpialidocious! |
If I use the command, grep -o -f pattern.txt file.txt it only prints the patterns that are found in the file.txt and does not print the entire line.
If I use the command grep -w -f pattern.txt file.txt it There are still lines that show up that do not contain the patterns.