The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Counting the number of occurances of all characters (a-z) in a string rsendhilmani Shell Programming and Scripting 5 08-05-2008 09:10 AM
Counting files in one directory matrixtlm UNIX for Dummies Questions & Answers 10 06-15-2007 04:14 PM
Help with counting files please gerard1 Shell Programming and Scripting 6 09-25-2006 10:37 AM
Counting lines and files jorge.ferreira UNIX for Dummies Questions & Answers 6 12-11-2003 08:24 AM
counting files Edy UNIX for Dummies Questions & Answers 5 06-28-2001 08:26 AM

Closed Thread
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 06-25-2001
Registered User
 

Join Date: Jun 2001
Posts: 2
Question Counting Occurances in Two Files

I have two files I want to compare, one is a list of variables and the other is a text file COBOL program.
Basically what I want to do is display only those variables that appear in the COBOL program only once. However I would also accept a count of each variable as it appears in the COBOL program.

fgrep –f VAR TEST.CBL
will display the lines of the code that match the variable file, however what I need is to locate those variables that have only one match.

Any ideas?
Forum Sponsor
  #2  
Old 06-26-2001
PxT's Avatar
PxT PxT is offline
Registered User
 

Join Date: Oct 2000
Location: Sacramento, CA
Posts: 909
I dont think you can do it directly with grep. How about:

Code:
#!/bin/ksh
for f in `cat VAR`
do
  COUNT=`grep $f TEST.CBL | wc -l`
  if [[ $COUNT -eq 1 ]]
  then
     echo $f
  fi
done
  #3  
Old 06-26-2001
Registered User
 

Join Date: Jun 2001
Posts: 2
Works great!
Thank you PxT!
Google The UNIX and Linux Forums
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 03:16 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0