Sponsored Content
Top Forums Shell Programming and Scripting number of occurences of a string Post 302098395 by vino on Monday 4th of December 2006 02:58:30 AM
Old 12-04-2006
Do you have grep -o flag ?

Code:
grep -o "nasa" input.txt | wc -l

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Counting number of occurences

Hi All, I have to count the number of occurences of the character " ; " in a given line. I had used the following awk command to achieve the same echo $KOP.dat|awk '{split($1,my,";"); for(i in my)c++ }END{print c-1}' My file KOP.dat had the following data ... (1 Reply)
Discussion started by: kingofprussia
1 Replies

2. Shell Programming and Scripting

How to count the number of occurences of this pattern?

Hi all, I have a pattern like this in a file: 123 4 56 789 234 5 67 789 121 3 56 789 222 4 65 789 321 6 90 100 478 8 40 789 243 7 80 789 How can I count the number of occurences of '789' (4th column) in this set...? Thanks for all your help! K (7 Replies)
Discussion started by: kripssmart
7 Replies

3. Shell Programming and Scripting

counting the number of occurences

say i've got a text file with >10million sequences: ssss ssss tttttt uuuuuu uuuuuu uuuuuu ... I'd like to convert the file so that the output will report the number of occurence right by each sequence: 2 ssss 2 ssss 1 tttttt 3 uuuuuu 3 uuuuuu 3 uuuuuu .... (3 Replies)
Discussion started by: johjoh
3 Replies

4. UNIX for Dummies Questions & Answers

Count number of occurences of a word

I want to count the number of occurences of say "200" in a file but that file also contains various stuff including dtaes like 2007 or smtg like 200.1 so count i am getting by doing grep -c "word" file is wrong Please help!!!!! (8 Replies)
Discussion started by: shikhakaul
8 Replies

5. Shell Programming and Scripting

awk counting number of occurences

Hi, I am trying to count the max number of occurences of field1 in my apache log example: 10.0.0.1 field2 field3 10.0.0.2 filed2 field3 10.0.0.1 field2 field3 10.0.0.1 field2 field3 awk result to print out only the most occurence of field1 and number of occurence and field1 is... (3 Replies)
Discussion started by: phamp008
3 Replies

6. Shell Programming and Scripting

to count the number of occurences of a column value

im trying to count the number of occurences of column 2 value(starting from KKK*) of the below file, file.txt using the code cat file.txt | awk ' BEGIN { print "Category Counts"} {FS=","} {NR > 2} { cats = cats + 1} END { for(c in cats) { print c, "=", cats} } ' but its returning as ... (6 Replies)
Discussion started by: michaelrozar17
6 Replies

7. UNIX for Dummies Questions & Answers

Number of word occurences in a file?

Hello world, Can anybody tell me how to count how many times does a word repeat in a file? There have been many threads on this but they all are heavy loads of Scripting for a starter like me. :D So, I sat down today and after some hours of reading man pages, I found a simple one-line... (18 Replies)
Discussion started by: satish51392111
18 Replies

8. Shell Programming and Scripting

Count number of occurences using awk

Hi Guys, I have 2 files like below file1 xx yy file2 b yy b2 xx c1 yy xx yy Now I want an idea which can count occurences of text from file1 and file2 so outbout would be kind of (9 Replies)
Discussion started by: prashant2507198
9 Replies

9. Shell Programming and Scripting

Count and print the number of occurences

I have some files as shown below GLL ALM 654-656 654 656 SEM LYG 655-657 655 657 SEM LYG 655-657 655 657 ALM LEG 656-658 656 658 ALM LEG 656-658 656 658 ALM LEG 656-658 656 658 LEG LEG 658-660 658 660 LEG LEG 658-660 658 660 The value of GLL is... (5 Replies)
Discussion started by: arch
5 Replies

10. Shell Programming and Scripting

Number of Consecutive Occurences

:b: Hi Folks, I have a requirement to find the number of consecutive occurences based on month. Here is the below sample of my requirement. I have say four columns CARUSERNAME BRAND_CODE MONTH YEAR Below is sample Data John|C|JAN|2013 Tim|C|FEB|2013 Tom|C|Mar|2013 Ron|C|Apr|2013... (4 Replies)
Discussion started by: dinesh1985
4 Replies
pmccabe(1)						      General Commands Manual							pmccabe(1)

NAME
pmccabe - calculate McCabe cyclomatic complexity or non-commented line counts for C and C++ programs SYNOPSIS
pmccabe [-bCdfFntTvV?] [file(s)] DESCRIPTION
pmccabe processes the named files, or standard input if none are named. In default mode it calculates statistics including McCabe cyclo- matic complexity for each function. The files are expected to be either C (ANSI or K&R) or C++. -? Print an informative usage message. -v Print column headers -V Print pmccabe version number De-commenting mode -d Intended to help count non-commented source lines via something like: pmccabe -d *.c | grep -v '^[<blank><tab>]*$' | wc -l Comments are removed, cpp directives are replaced by cpp, string literals are replaced by STRINGLITERAL, character constants are replaced by CHARLITERAL. The resulting source code is much easier to parse. This is the first step performed by pmccabe so that its parser can be simpler. None of the other options work sensibly with -d. Line-counting mode -n Counts non-commented source lines. The output format is identical to that of the anac program except that column headers and totals must be requested if desired. If you want column headers add -v. If you want totals add -t. If all you want is totals add -T. Complexity mode (default) -C Custom output format - don't use it. -c Report non-commented, non-blank lines per function (and file) instead of the raw number of lines. Note that pre-processor direc- tives are NOT counted. -b Output format compatible with compiler error browsing tools which understand "classic" compiler errors. Numerical sorting on this format is possible using: sort -n +1 -t% -t Print column totals. Note the total number of lines is *NOT* the number of non-commented source lines - it's the same as would be reported by "wc -l". -T Print column totals *ONLY*. -f Include per-file totals along with the per-function totals. -F Print per-file totals but NOT per-function totals. Parsing pmccabe ignores all cpp preprocessor directives - calculating the complexity of the appearance of the code rather than the complexity after the preprocessor mangles the code. This is especially important since simple things like getchar(3) expand into macros which increase com- plexity. Output Format A line is written to standard output for each function found of the form: Modified McCabe Cyclomatic Complexity | Traditional McCabe Cyclomatic Complexity | | # Statements in function | | | First line of function | | | | # lines in function | | | | | filename(definition line number):function | | | | | | 5 6 11 34 27 gettoken.c(35): matchparen Column 1 contains cyclomatic complexity calculated by adding 1 (for the function) to the occurences of for, if, while, switch, &&, ||, and ?. Unlike "normal" McCabe cyclomatic complexity, each case in a switch statement is not counted as additional complexity. This treatment of switch statements and complexity may be more useful than the "normal" measure for judging maintenance effort and code difficulty. Column 2 is the cyclomatic complexity calculated in the "usual" way with regard to switch statements. Specifically it is calculated as in column 1 but counting each case rather than the switch and may be more useful than column 1 for judging testing effort. Column 3 contains a statement count. It is calculated by adding each occurence of for, if, while, switch, ?, and semicolon within the function. One possible surprise is that for statements have a minimum statement count of 3. This is realistic since for(A; B; C){...} is really shorthand for A; while (B) { ... C;}. The number of statements within a file is the sum of the number of statements for each func- tion implemented within that file, plus one for each of those functions (because functions are statements too), plus one for each other file-scoped statement (usually declarations). Column 4 contains the first line number in the function. This is not necessarily the same line on which the function name appears. Column 5 is the number of lines of the function, from the number in column 4 through the line containing the closing curly brace. The final column contains the file name, line number on which the function name occurs, and the name of the function. APPLICATIONS
The obvious application of pmccabe is illustrated by the following which gives a list of the "top ten" most complex functions: pmccabe *.c | sort -nr | head -10 Many files contain more than one C function and sometimes it would be useful to extract each function separately. matchparen() (see exam- ple output above) can be extracted from gettoken.c by extracting 27 lines starting with line 34. This can form the basis of tools which operate on functions instead of files (e.g., use as a front-end for diff(1)). DIAGNOSTICS
pmccabe returns a nonzero exit status if files could not be opened and upon encountering some parsing errors. Error messages to standard error, usually explaining that the parser is confused about something, mimic classic C compiler error messages. WARNINGS
pmccabe is confused by unmatched curly braces or parentheses which sometimes occur with hasty use of cpp directives. In these cases a diagnostic is printed and the complexity results for the files named may be unreliable. Most times the "#ifdef" directives may be modified such that the curly braces match. Note that if pmccabe is confused by a cpp directive, most pretty printers will be too. In some cases, preprocessing with unifdef(1) may be appropriate. Statement counting could arguably be improved by: counting occurences of the comma operator, multiple assignments, assignments within con- ditional tests, and logical conjunction. However since there is no crisp statement definition from the language or from people I've queried, statement counting will probably not be improved. If you have a crisp definition I'll be happy to consider it. Templates cause pmccabe's scanner to exit. It's a shame that ctags output isn't provided. AUTHOR
Paul Bame SEE ALSO
codechanges(1), decomment(1), vifn(1), sort(1), diff(1), wc(1), grep(1), unifdef(1), head(1), anac(1) http://parisc-linux.org/~bame/pmccabe/ HP
12Feb2003 pmccabe(1)
All times are GMT -4. The time now is 10:02 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy