grep a certain file using the string file another textfile


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting grep a certain file using the string file another textfile
# 1  
Old 05-11-2009
grep a certain file using the string file another textfile

THis is my code

Code:
echo "Filter1: " $F1 " file/s"  >> $FILE
for x in `cat cg.txt`; do
echo $x
        z=`grep $x tmp2.txt | wc -l`
        if [ $z -eq 0 ]; then
                echo "\\t" $x ": " $z " file/s" >> $FILE
        fi
done

The bolded line is not working. I want to grep a certain file using the string that got from the file cg.txt.
how am I suppose to access the string from another file, and encapsulate it inside the grep function.
# 2  
Old 05-11-2009
Hi izuma,

The code you hav posted working fine for me .

is it what your expecting ?...

ex :

TEST>cat cg.txt
Rama
seetha

TEST>cat tmp2.txt
Rama seetha dadfdf dgg
fdgdfg
no mtch
Rama dsd lalal

TEST>cat script.sh

for i in `cat cg.txt`
do
z=`grep $i tmp2* | wc -l`
echo "for the string : $i -> $z "
done

TEST>./script.sh

for the string : Rama -> 2
for the string : seetha -> 1

Last edited by panyam; 05-11-2009 at 07:04 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace string of a file with a string of another file for matches using grep,sed,awk

I have a file comp.pkglist which mention package version and release . In 'version change' and 'release change' line there are two versions 'old' and 'new' Version Change: --> Release Change: --> cat comp.pkglist Package list: nss-util-devel-3.28.4-1.el6_9.x86_64 Version Change: 3.28.4 -->... (1 Reply)
Discussion started by: Paras Pandey
1 Replies

2. Linux

Split a large textfile (one file) into multiple file to base on ^L

Hi, Anyone can help, I have a large textfile (one file), and I need to split into multiple file to break each file into ^L. My textfile ========== abc company abc address abc contact ^L my company my address my contact my skills ^L your company your address ========== (3 Replies)
Discussion started by: fspalero
3 Replies

3. Shell Programming and Scripting

Grep string in files and list file names that contain the string

Hi, I have a list of zipped files. I want to grep for a string in all files and get a list of file names that contain the string. But without unzipping them before that, more like using something like gzcat. My OS is: SunOS test 5.10 Generic_142900-13 sun4u sparc SUNW,SPARC-Enterprise (8 Replies)
Discussion started by: apenkov
8 Replies

4. Shell Programming and Scripting

need help in Grep a string in the log file

logfile="/var/tmp.log" output=$(grep "ERROR" $logfile) if then echo "exceptions logged , please check /var/tmp.log for more details" |\ mail -s "exceptions logged , please check /var/tmp.log on for more details" $DL else echo "not found" fi Somehow its not working as... (5 Replies)
Discussion started by: ajothi
5 Replies

5. Shell Programming and Scripting

grep exact string from files and write to filename when string present in file

I am attempting to grep an exact string from a series of files within a directory and append that output to the filename when it is present in the file. I've been after this all day with no luck. Thanks for your help in advance :wall:. (4 Replies)
Discussion started by: JC_1
4 Replies

6. Shell Programming and Scripting

grep a string in a file

Hi , i'm trying to create a code for the belwo scenario. i have a data in a file file.txt like below. ram dept comp shyam field comp Now i need write a code to find the string which is always 2 lines before the string "comp" Can you please help me in this. Thanks in advance (15 Replies)
Discussion started by: p.bhaskar
15 Replies

7. Shell Programming and Scripting

Grep a string from input file and delete next three lines including the line contains string in xml

Hi, 1_strings file contains $ cat 1_strings /home/$USER/Src /home/Valid /home/Review$ cat myxml <projected value="some string" path="/home/$USER/Src"> <input 1/> <estimate value/> <somestring/> </projected> <few more lines > <projected value="some string" path="/home/$USER/check">... (4 Replies)
Discussion started by: greet_sed
4 Replies

8. Shell Programming and Scripting

Find a string in textfile, erase $num lines after that string

I have a textfile containing text similar to the following pattern: STRING1 UNIQUE_STRING1 STRING2 STRING3 STRING4 STRING5 STRING1 UNIQUE_STRING2 STRING2 STRING3 STRING4 STRING5 STRING1 UNIQUE_STRING3 STRING2 STRING3 (6 Replies)
Discussion started by: ilcsfe
6 Replies

9. Shell Programming and Scripting

grep string from a file

hi everyone, 1.txt 12 34 56 2.txt 456----aa abc;b;b;b 34;a;a;a;a output is 456----aa 34;a;a;a;a (11 Replies)
Discussion started by: jimmy_y
11 Replies

10. Shell Programming and Scripting

If else - grep a string in a file

Hi all, I would want to recieve notification only if there are sessions block in our databases. This is my script, but it's not working. No matter what is the contents in the $OUTFILE, I get emails. /usr/bin/cat $OUTFILE | read selected if then echo "No session is blocked" else ... (7 Replies)
Discussion started by: *Jess*
7 Replies
Login or Register to Ask a Question