Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Counting Occurances in Two Files Post 3200 by PxT on Tuesday 26th of June 2001 11:03:23 AM
Old 06-26-2001
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

 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

counting files

Which one line command can count and print to the screen the number of files containing "a" or "A" in their name (5 Replies)
Discussion started by: Edy
5 Replies

2. Shell Programming and Scripting

Help with counting files please

Hi all. If I have a unix directory with multiple files, lets say, I have some with .dat extensions, some with .txt extensions, etc etc. How in a script would I provide a count of all the different file types (so, the different extensions, I guess) in the directory?? So if I had: test.dat... (6 Replies)
Discussion started by: gerard1
6 Replies

3. Solaris

Counting up files

Hi, I have a load of if statements that look for files in a directory, I want to be able to count them up and the total files confirmed in an email? I ahve tried expr but i this does not work and it only reads in the first if and ignores the rest. Please see script, #!/bin/ksh ... (2 Replies)
Discussion started by: Pablo_beezo
2 Replies

4. Shell Programming and Scripting

Counting the number of occurances of all characters (a-z) in a string

Hi, I am trying out different scripts in PERL. I want to take a line/string as an input from the user and count the number of occurrances of all the alphabets (a..z) in the string. I tried doingit like this : #! /opt/exp/bin/perl print "Enter a string or line : "; $string = <STDIN>; chop... (5 Replies)
Discussion started by: rsendhilmani
5 Replies

5. Shell Programming and Scripting

multiple files: counting

In a directory, I have 5000 multiple files that contains around 4000 rows with 10 columns in each file containing a unique string 'AT' located at 4th column. OM 3328 O BT 268 5.800 7.500 4.700 0.000 1.400 OM 3329 O BT 723 8.500 8.900... (7 Replies)
Discussion started by: asanjuan
7 Replies

6. Shell Programming and Scripting

Counting Files

In a script, how would I go about finding the number of files for the first parameter after my script name? For instance, my script name is myscript.sh and the folder I am checking is not the current working directory, lets say it's folder1. so I type myscript.sh folder1 This script below... (2 Replies)
Discussion started by: Confirmed104
2 Replies

7. UNIX for Dummies Questions & Answers

Counting files without ls or wc

i need to write a shell script to "count the number of files in the current directory but without using either ls or wc command"..... please help! (1 Reply)
Discussion started by: lexicon
1 Replies

8. Shell Programming and Scripting

Count the number of occurances for multiple files

I have some text files as shown below. I would like to add the values of each string. Your help would be appreciated!! file1.txt SUS 2 PRS 2 ALI 1 PRS 1 GLK 2 file2.txt PRS 3 GLK 6 SUS 18 Desired output SUS 20 PRS 6 (2 Replies)
Discussion started by: arch
2 Replies

9. Shell Programming and Scripting

2 files replace multiple occurances based on a match

Hi All, I need some help trying to achieve the below but everything I've tried has failed, I have 2 files which i'm trying to carry out a match based on the first column from file 1, take that value find it in file 2 if found replace it with the second column from File 1 Lookup File: File 1... (3 Replies)
Discussion started by: mutley2202
3 Replies
head(1) 						      General Commands Manual							   head(1)

NAME
head - Displays the beginning of files SYNOPSIS
Current Syntax head [-c bytes] [-n lines] [file...] Obsolescent Syntax head [-lines] [file...] STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: head: XCU5.0 Refer to the standards(5) reference page for more information about industry standards and associated tags. OPTIONS
The default count is 10. [Tru64 UNIX] Specifies the number of bytes to display. If the last byte written is not a newline character, a newline character is appended to the output. Specifies the number of lines to display Works exactly as -n lines. Obsolescent. OPERANDS
Path name of the input file. If you do not specify a file, head reads standard input. DESCRIPTION
The head command copies the standard input to standard output, ending output of each file at the specified point. NOTES
The obsolescent form is subject to withdrawal at any time. EXIT STATUS
The following exit values are returned: Successful completion. An error occurred. EXAMPLES
To display the first 5 lines of a file called test, enter: head -n 5 test To display the first ten lines of all files (except those with a name beginning with a period), enter: head * ENVIRONMENT VARIABLES
The following environment variables affect the execution of head: Provides a default value for the internationalization variables that are unset or null. If LANG is unset or null, the corresponding value from the default locale is used. If any of the internationalization vari- ables contain an invalid setting, the utility behaves as if none of the variables had been defined. If set to a non-empty string value, overrides the values of all the other internationalization variables. Determines the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as opposed to multibyte characters in arguments and input files). Determines the locale for the format and contents of diagnostic messages written to standard error. Determines the location of message catalogues for the processing of LC_MESSAGES. SEE ALSO
Commands: cat(1), more(1), pg(1), sed(1), tail(1) Standards: standards(5) head(1)
All times are GMT -4. The time now is 09:30 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy