Sponsored Content
Top Forums Shell Programming and Scripting Count occurances of X Y Z in a file in 1 go. Post 302292924 by msullivan on Monday 2nd of March 2009 02:39:52 AM
Old 03-02-2009
Superb!! Thanks ripat!
I goes to about 3.5% CPU Utilization, but finishes in about 15 seconds, which is fair game for me.

Output:
502 3
304 1359
503 88
404 467
200 31817
500 301
302 207

*Edit: But if there is another way to do it which uses very little CPU, please feel free to post a reply

Last edited by msullivan; 03-02-2009 at 04:03 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find occurances of a directory and count

I am writing my first shell script to do the following: Find all occurrences of a directory from the pwd Delete the directory (which is a hidden directory) Provide feedback w/ the number of directories deleted The problems I am having are two-fold: The user may not have the appropriate... (2 Replies)
Discussion started by: stringman
2 Replies

2. Shell Programming and Scripting

count the number chracters occurances in a line

Hi Could anybody tell me how to count the number of occurances of a character within a LINE. actually i have a single line with words seperated with '+' chracter e.g. abc+def+ghj+jkl+asd i want to separte the words above. Please provide the necessary logic in the form of a SHELL... (6 Replies)
Discussion started by: skyineyes
6 Replies

3. Shell Programming and Scripting

Count occurances of a character in a file

I want to find the number of occurences of a character in a file. How do i do it. Eg: $cat file1.txt Welcome to World of Unix. $ If i want to find the occurences of 'o' then I should be getting 3. Thanks. (6 Replies)
Discussion started by: Shivdatta
6 Replies

4. UNIX for Dummies Questions & Answers

Count occurances in a file

Hi, I have a fixed width file in the following format Sr.No A.No Name 1 2 PPP 3 4 PPP 5 6 TTT 7 8 OOO 9 10 OOO 11 12 OOO The 3rd column starts at position 10 and ends at 15. I want to count the number of occurances of each Name and output to a file Example in the... (2 Replies)
Discussion started by: samit_9999
2 Replies

5. Shell Programming and Scripting

nawk-how count the number of occurances of a pattern, when don't know the pattern

I've written a script to count the total size of SAN storage LUNs, and also display the LUN sizes. From server to server, the LUNs sizes differ. What I want to do is count the occurances as they occur and change. These are the LUN sizes: 49.95 49.95 49.95 49.95 49.95 49.95 49.95 49.95... (2 Replies)
Discussion started by: cyber111
2 Replies

6. Shell Programming and Scripting

How to count number of occurances of string in a file?

Gurus, Need little guidance. I have A.txt and B.txt file. B.txt file contains Unique strings. Sample content of B.txt file for which i cut the fourth column uniquely and output directed to B.txt file And A.txt file contains the above string as a fourth column which is last column. So A.txt... (7 Replies)
Discussion started by: Shirisha
7 Replies

7. Shell Programming and Scripting

Get number of occurances in a file

I want to get the count of occurance of a user in a file. abc abc bcd bcd bcd xyz The result should be like abc 2 bcd 3 xyz 1 (2 Replies)
Discussion started by: Sanjeev Yadav
2 Replies

8. Shell Programming and Scripting

Count the occurances of numbers

I have a file as shown below. I need to count the unique occurrences of numbers in the first and second column only if the third column is <= 10. Otherwise print the corresponding numbers as zero. Thanks in advance!:) 58 80 40.74 76 80 9.78 76 80 8 12 6 9 30 28 8.23 45 12 ... (13 Replies)
Discussion started by: andreaalex
13 Replies

9. 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

10. UNIX for Beginners Questions & Answers

Grep pattern file and count occurances

Guys I am trying grep to read from pattern file and count occurances of each word. input is firstplace secondplace secondpot patternfile is place first second i want the following. 1-count number of times keywords in patternfile occurs in begining of each line in input file. so... (12 Replies)
Discussion started by: ahfze
12 Replies
httpd_util(3erl)					     Erlang Module Definition						  httpd_util(3erl)

NAME
httpd_util - Miscellaneous utility functions to be used when implementing Erlang Web server API modules. DESCRIPTION
This module provides the Erlang Web Server API module programmer with miscellaneous utility functions. EXPORTS
convert_request_date(DateString) -> ErlDate|bad_date Types DateString = string() ErlDate = {{Year,Month,Date},{Hour,Min,Sec}} Year = Month = Date = Hour = Min = Sec = integer() convert_request_date/1 converts DateString to the Erlang date format. DateString must be in one of the three date formats that is defined in the RFC 2616. create_etag(FileInfo) -> Etag Types FileInfo = file_info() Etag = string() create_etag/1 calculates the Etag for a file, from its size and time for last modification. fileinfo is a record defined in ker- nel/include/file.hrl decode_hex(HexValue) -> DecValue Types HexValue = DecValue = string() Converts the hexadecimal value HexValue into its decimal equivalent ( DecValue ). day(NthDayOfWeek) -> DayOfWeek Types NthDayOfWeek = 1-7 DayOfWeek = string() day/1 converts the day of the week ( NthDayOfWeek ) as an integer (1-7) to an abbreviated string, that is: 1 = "Mon", 2 = "Tue", ..., 7 = "Sat". flatlength(NestedList) -> Size Types NestedList = list() Size = integer() flatlength/1 computes the size of the possibly nested list NestedList . Which may contain binaries. hexlist_to_integer(HexString) -> Number Types Number = integer() HexString = string() hexlist_to_integer Convert the Hexadecimal value of HexString to an integer. integer_to_hexlist(Number) -> HexString Types Number = integer() HexString = string() integer_to_hexlist/1 Returns a string that represents the Number in a Hexadecimal form. lookup(ETSTable,Key) -> Result lookup(ETSTable,Key,Undefined) -> Result Types ETSTable = ets_table() Key = term() Result = term() | undefined | Undefined Undefined = term() lookup extracts {Key,Value} tuples from ETSTable and returns the Value associated with Key . If ETSTable is of type bag only the first Value associated with Key is returned. lookup/2 returns undefined and lookup/3 returns Undefined if no Value is found. lookup_mime(ConfigDB,Suffix) lookup_mime(ConfigDB,Suffix,Undefined) -> MimeType Types ConfigDB = ets_table() Suffix = string() MimeType = string() | undefined | Undefined Undefined = term() lookup_mime returns the mime type associated with a specific file suffix as specified in the mime.types file (located in the config directory ). lookup_mime_default(ConfigDB,Suffix) lookup_mime_default(ConfigDB,Suffix,Undefined) -> MimeType Types ConfigDB = ets_table() Suffix = string() MimeType = string() | undefined | Undefined Undefined = term() lookup_mime_default returns the mime type associated with a specific file suffix as specified in the mime.types file (located in the config directory ). If no appropriate association can be found the value of DefaultType is returned. message(StatusCode,PhraseArgs,ConfigDB) -> Message Types StatusCode = 301 | 400 | 403 | 404 | 500 | 501 | 504 PhraseArgs = term() ConfigDB = ets_table Message = string() message/3 returns an informative HTTP 1.1 status string in HTML. Each StatusCode requires a specific PhraseArgs : 301 : string() : A URL pointing at the new document position. 400 | 401 | 500 : none (No PhraseArgs ) 403 | 404 : string() : A Request-URI as described in RFC 2616. 501 : {Method,RequestURI,HTTPVersion} : The HTTP Method , Request-URI and HTTP-Version as defined in RFC 2616. 504 : string() : A string describing why the service was unavailable. month(NthMonth) -> Month Types NthMonth = 1-12 Month = string() month/1 converts the month NthMonth as an integer (1-12) to an abbreviated string, that is: 1 = "Jan", 2 = "Feb", ..., 12 = "Dec". multi_lookup(ETSTable,Key) -> Result Types ETSTable = ets_table() Key = term() Result = [term()] multi_lookup extracts all {Key,Value} tuples from an ETSTable and returns all Values associated with the Key in a list. reason_phrase(StatusCode) -> Description Types StatusCode = 100| 200 | 201 | 202 | 204 | 205 | 206 | 300 | 301 | 302 | 303 | 304 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 410 411 | 412 | 413 | 414 415 | 416 | 417 | 500 | 501 | 502 | 503 | 504 | 505 Description = string() reason_phrase returns the Description of an HTTP 1.1 StatusCode , for example 200 is "OK" and 201 is "Created". Read RFC 2616 for further information. rfc1123_date() -> RFC1123Date rfc1123_date({{YYYY,MM,DD},{Hour,Min,Sec}}}) -> RFC1123Date Types YYYY = MM = DD = Hour = Min =Sec = integer() RFC1123Date = string() rfc1123_date/0 returns the current date in RFC 1123 format. rfc_date/1 converts the date in the Erlang format to the RFC 1123 date format. split(String,RegExp,N) -> SplitRes Types String = RegExp = string() SplitRes = {ok, FieldList} | {error, errordesc()} Fieldlist = [string()] N = integer split/3 splits the String in N chunks using the RegExp . split/3 is is equivalent to regexp:split/2 with one exception, that is N defines the number of maximum number of fields in the FieldList . split_script_path(RequestLine) -> Splitted Types RequestLine = string() Splitted = not_a_script | {Path, PathInfo, QueryString} Path = QueryString = PathInfo = string() split_script_path/1 is equivalent to split_path/1 with one exception. If the longest possible path is not a regular, accessible and executable file not_a_script is returned. split_path(RequestLine) -> {Path,QueryStringOrPathInfo} Types RequestLine = Path = QueryStringOrPathInfo = string() split_path/1 splits the RequestLine in a file reference ( Path ) and a QueryString or a PathInfo string as specified in RFC 2616. A QueryString is isolated from the Path with a question mark ( ? ) and PathInfo with a slash (/). In the case of a QueryString , everything before the ? is a Path and everything after a QueryString . In the case of a PathInfo the RequestLine is scanned from left-to-right on the hunt for longest possible Path being a file or a directory. Everything after the longest possible Path , iso- lated with a / , is regarded as PathInfo . The resulting Path is decoded using decode_hex/1 before delivery. strip(String) -> Stripped Types String = Stripped = string() strip/1 removes any leading or trailing linear white space from the string. Linear white space should be read as horizontal tab or space. suffix(FileName) -> Suffix Types FileName = Suffix = string() suffix/1 is equivalent to filename:extension/1 with one exception, that is Suffix is returned without a leading dot ( . ). SEE ALSO
httpd(3erl) Ericsson AB inets 5.5.2 httpd_util(3erl)
All times are GMT -4. The time now is 06:44 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy