Sponsored Content
Top Forums UNIX for Beginners Questions & Answers What script would I use to count the number of a term and its opposite? Post 303041738 by RudiC on Tuesday 3rd of December 2019 05:43:41 AM
Old 12-03-2019
With grep and friends you'll get one count per run, so you'll have to go through the file twice. Might not be a problem with small files, but resource consumption increases with sizes. Taylor your solution with a little script like e.g.
Code:
awk -v"PAT=done" '$0 ~ PAT {PRES++; next} {ABS++} END {print PRES ORS ABS}' file

or, if you need it case insensitive,

Code:
awk -v"PAT=done" 'tolower($0) ~ tolower(PAT) {PRES++; next} {ABS++} END {print PRES ORS ABS}' file

These 2 Users Gave Thanks to RudiC For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to count unique number of user loged in

Hi all, I am taking my first course in unix and having some problems. I would line to create a scrip that does the following: 1) will tell me the number of users logged in. If a user is logged more than once just count it only ones. 2) want to be able to display the number of users that... (1 Reply)
Discussion started by: elchalateco
1 Replies

2. Programming

Create a Term & Run chars on this Term

hi floks ! i'd like to know how can i transmete a character or a string from my source code to a term and make it interpret or un by the shell wich is running in my term. I'd like to create a Term from my code (and get its file descriptor) and then transmete each char typed on the keyboard to... (1 Reply)
Discussion started by: the_tical
1 Replies

3. Shell Programming and Scripting

Search term and output term in desired field

Hi All, I have an input_file below and i would like to use Perl to search for the term "aaa" and output the 3rd term in the same row as "aaa".For Example, i want to search for the term "ddd" and would want the code to ouput the 3rd term in the same row which is "fff". Can somebody help ? ... (28 Replies)
Discussion started by: Raynon
28 Replies

4. Shell Programming and Scripting

scripting - write a script that will count the number of times a particular word

hello everyone, I'm trying to learn some scripts but i cant get my head around two of them. 1. how can i write a script that will count the number of times a particular word is used in file? 2. how can i make a script that will take me to a web page from unix? if anyone could help it... (3 Replies)
Discussion started by: BigTool4u2
3 Replies

5. Shell Programming and Scripting

d. Write a shell script to count the number of accounts which belong to particular primary

guys, I am new shelll scripting.. this a question on passt exam paper, I was trying to solve it , I can not. the question is as follow? a. Write a shell script to count the number of accounts which belong to particular primary group in a standard UNIX system which uses local... (1 Reply)
Discussion started by: gurmad
1 Replies

6. Shell Programming and Scripting

perl script on how to count the total number of lines of all the files under a directory

how to count the total number of lines of all the files under a directory using perl script.. I mean if I have 10 files under a directory then I want to count the total number of lines of all the 10 files contain. Please help me in writing a perl script on this. (5 Replies)
Discussion started by: adityam
5 Replies

7. Shell Programming and Scripting

Need script to count specific word and iterate over number of files.

Hi Experts, I want to know the count of specific word in a file. I have almost 600+ files. So I want to loop thru each file and get the count of the specific word. Please help me on achieving this... Many thanks (2 Replies)
Discussion started by: elamurugu
2 Replies

8. Shell Programming and Scripting

count number of entries perl program or Unix script

Hi I have a file with number of entries name 1 123 name 1 345 name 1 65346 name2 3243 name2 24234 name 2 234234 so on ......... how to count total number of entries for name 1 and name2...and so on Please guide. (1 Reply)
Discussion started by: manigrover
1 Replies

9. Shell Programming and Scripting

Script to count number of files in directories

Hi All! I would like to have a script that will count the number of files at the top of the hour of soome directories and mail the results to me. I was thinking on : a=`/directory/subdirectory/ | wc -l` echo "/directory/subdirectory :$a" b=`/another_dir/subdir/ | wc -l` echo... (12 Replies)
Discussion started by: fretagi
12 Replies

10. UNIX for Dummies Questions & Answers

Script to count number of rows

Hi, I need a solaris shell script to read multiple files and count number of unique name rows(strings) from those files. The input and output should be like this Input: file 1 abc cde abc ... (9 Replies)
Discussion started by: ssk250
9 Replies
ABS(3)							     Linux Programmer's Manual							    ABS(3)

NAME
abs, labs, llabs, imaxabs - compute the absolute value of an integer SYNOPSIS
#include <stdlib.h> int abs(int j); long int labs(long int j); long long int llabs(long long int j); #include <inttypes.h> intmax_t imaxabs(intmax_t j); Feature Test Macro Requirements for glibc (see feature_test_macros(7)): llabs(): _XOPEN_SOURCE >= 600 || _ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L; or cc -std=c99 DESCRIPTION
The abs() function computes the absolute value of the integer argument j. The labs(), llabs() and imaxabs() functions compute the absolute value of the argument j of the appropriate integer type for the function. RETURN VALUE
Returns the absolute value of the integer argument, of the appropriate integer type for the function. CONFORMING TO
SVr4, POSIX.1-2001, 4.3BSD, C99. C89 only includes the abs() and labs() functions; the functions llabs() and imaxabs() were added in C99. NOTES
Trying to take the absolute value of the most negative integer is not defined. The llabs() function is included in glibc since version 2.0, but is not in libc5 or libc4. The imaxabs() function is included in glibc since version 2.1.1. For llabs() to be declared, it may be necessary to define _ISOC99_SOURCE or _ISOC9X_SOURCE (depending on the version of glibc) before including any standard headers. GCC handles abs() and labs() as built-in functions. GCC 3.0 also handles llabs() and imaxabs() as built-ins. SEE ALSO
cabs(3), ceil(3), fabs(3), floor(3), rint(3) COLOPHON
This page is part of release 3.27 of the Linux man-pages project. A description of the project, and information about reporting bugs, can be found at http://www.kernel.org/doc/man-pages/. GNU
2010-09-20 ABS(3)
All times are GMT -4. The time now is 10:53 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy