grep Patterns from File
Hello,
I am interested in using the grep method in the shell of my CentOS machine to obtain patterns from a file and use them to search through another file and highlight the patterns found. For example: pattern file: one two three test file: AAAAAAAAAAAAAAAAAAAAAoneAAAAAAAAAAAAAAAAthreeAAAAAAAAAAAA Any suggestions? |
You should get some ideas from this thread:
http://www.linuxquestions.org/questi...script-821689/ Then, show is what you've come up with if you're still having troubles, and we shall see if we can help you fix it. |
If you're doing a lot of this, you might want to use Perl. I've done something like that in the past where the perl script uses a text file as a dictionary of things to grep for.
|
I also think Perl will be better for this. And still, you didn't really explain your problem well enough.
|
Perl is certainly capable of meeting the stated requirements, and indeed is probably a good tool if the problem expands very much. Still, grep in a bash script is more than up to the task. Without actually doing the OP's (home)work, he wants to load a variable from the pattern file in a while loop, and for each iteration of the loop, use that variable as the pattern argument to grep. Should take about 3 or four lines.
--- rod. |
Quote:
Code:
shopt -s extglob |
Quote:
Code:
grep --color -f pattern_file test_file |
Quote:
|
Quote:
|
All times are GMT -5. The time now is 01:56 AM. |