Reading from a text file then /grep/output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Reading from a text file then /grep/output
# 1  
Old 06-17-2009
Reading from a text file then /grep/output

I have a list of words that I want to grep in many files to see which ones have it and which ones dont.

in the text file I have all the words listed line by line, ex:

list.txt:

check
try this
word1
word2
open space
list ..

I want to grep each line one by one.
like I want it to

grep "check" *.log
grep "try this" *.log
grep "word1" *.log .. etc how can I do this?

and maybe write the output to a file.
# 2  
Old 06-17-2009
Code:
egrep -f list.txt *.log

# 3  
Old 06-17-2009
Quote:
Originally Posted by vgersh99
Code:
egrep -f list.txt *.log

I tried that before but it gives me

egrep -f list.txt *.log
egrep: syntax error
# 4  
Old 06-17-2009
works fine under Solaris.
try it with 'grep'.
look into your grep (grep, egrep, fgrep etc) man pages to find a similar switch:
Code:
     -f file
           Take the list of full regular expressions from file.

# 5  
Old 06-17-2009
Thanks,
Now I can list the matching words in the list.txt

Last edited by s3rro; 06-17-2009 at 09:14 PM..
# 6  
Old 06-17-2009
How can I find the non-matching words(lines) which are in list.txt but not in x.log ?
# 7  
Old 06-17-2009
Quote:
Originally Posted by s3rro
How can I find the non-matching words(lines) which are in list.txt but not in x.log ?
look for '-v' in 'man grep'
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

How to write in other language in text/xml file by reading english text/xml file using C++?

Hello Team, I have 2 files.one contains english text and another contains Japanese. so i have to read english text and replace the text with Japanesh text in third file. Basically, I need a help to write japanese language in text/xml file.I heard wstring does this.Not sure how do i write... (2 Replies)
Discussion started by: SA_Palani
2 Replies

2. Shell Programming and Scripting

Reading a value from another text file

I am having a text file best = 100 genre = 75 group = 53 . . and so on I need to read those values (100,75,53,...) from my shell script. I have to do the same function for all the variables. So in my script i used for loop to do the same. for { a=best b=100 } Video tutorial on... (3 Replies)
Discussion started by: kishorekumar87
3 Replies

3. Shell Programming and Scripting

Reading UNIX commands from file and redirecting output to a file

Hi All I have written the following script: #!/bin/ksh while read cmdline do echo `$cmdline` pid="$cmdline" done<commands.txt =========== commands.txt contains: ps -ef | grep abc | grep xyz |awk '{print $2}; My objective is to store the o/p of the command in a variable and do... (8 Replies)
Discussion started by: rahulparo
8 Replies

4. Shell Programming and Scripting

grep output of a text file

Hi. I have a unix script 'if' condition that greps through a file and searches for the strings ERROR and WARNING. if egrep -q 'ERROR|WARNING' myfile.txt; then When this 'if' condition is true then I want to be able to capture 10 lines before the string and 10 lines after the string. So... (6 Replies)
Discussion started by: buechler66
6 Replies

5. UNIX for Dummies Questions & Answers

Grab Portion of Output Text (sed, grep, awk?)

Alright, here's the deal. I'm running the following ruby script (output follows): >> /Users/name/bin/acweather.rb -z 54321 -o /Users/name/bin -c Clouds AND Sun 57/33 - Mostly sunny and cool I want to just grab the "57/33" portion, but that's it. I don't want any other portion of the line. I... (5 Replies)
Discussion started by: compulsiveguile
5 Replies

6. Shell Programming and Scripting

Dynamic output file generation using a input text file with predefined output format

Hi, I have two files , one file with data file with attributes that need to be sent to another file to generate a predefined format. Example: File.txt AP|{SSHA}VEEg42CNCghUnGhCVg== APVG3|{SSHA}XK|"password" AP3|{SSHA}XK|"This is test" .... etc --------- test.sh has... (1 Reply)
Discussion started by: hudson03051nh
1 Replies

7. Shell Programming and Scripting

grep reverses # output, but not text?

I have a working script to find out the IP of a hostname like this: #!/bin/bash h="www.google.com" echo $h j=`host $h | grep -o '\{1,3\}\.\{1,3\}\.\{1,3\}\.\{1,3\}'` echo "ip: $j" output ip: 74.125.19.99 the strange thing is if I use an IP instead of a hostname for $h, it inverts the... (2 Replies)
Discussion started by: unclecameron
2 Replies

8. Programming

reading a text file in c++

hello all , im trying to read a text file and display its contents. While i got the code running and the output was displayed perfectly for sometime , i started getting Abort(core dump) error . Am i missing something here ? im using HP-UX. #include <iostream.h> #include <fstream.h> #include... (1 Reply)
Discussion started by: vishy_85
1 Replies

9. UNIX for Dummies Questions & Answers

Help with reading text file

How can i have a while loop as follows while read inputline do <task> done < name_list and also store the values (delimited) on each line to temp variables so as to print them on screen as follows while read inputline do set name | cut -d "," -f1 name_list # #i know this is not... (1 Reply)
Discussion started by: bilal05
1 Replies

10. Shell Programming and Scripting

reading text file

I have a text file with 50 munbers. I wanna read these numbers and append "@yahoo.com" and send emails to them using shell scripting.......... How do i read the inetegres from the text file. (1 Reply)
Discussion started by: jaan
1 Replies
Login or Register to Ask a Question