Sponsored Content
Full Discussion: search and count
Top Forums UNIX for Advanced & Expert Users search and count Post 302284124 by curleb on Wednesday 4th of February 2009 10:41:44 PM
Old 02-04-2009
smells like homework, but it educated me on how to waste a few minutes:

Code:
me@where[]:
-> typeset -ix pipe_count=$(print "1|trunc(sysdate-1)|substring(pcol)" |tr "|" "\n" |wc -l )
me@where[]:
-> echo $pipe_count - 1 |bc
2

This is of course ksh only, but I'm sure that some of the others out there have other one-liners that could of assistance (awk, perl, whatever...). In fact, you could even boil it down to a one-liner here as well:

Code:
echo $(print "1|trunc(sysdate-1)|substring(pcol)" |tr "|" "\n" |wc -l ) - 1 |bc

What it does is break the input into records and then subtract one from the resulting line count. grep -c wouldn't work for you since it's line-based, and tr is fast enough. HTH...
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

search& count for the occurence of a word

Greetings, I need to search and count all the occurences of a word in all the files in a directory. Any suggestions greatly appreciated. Thanks (1 Reply)
Discussion started by: skoppana
1 Replies

2. Shell Programming and Scripting

pattern search and count

i want to search a word in a file and find the count of occurences even if pattern occures twice in a same line. for example file has the following content. yes no no nooo yees no yes if I search for "no" it should give count as 4 Pls help. Thanks (9 Replies)
Discussion started by: RahulJoshi
9 Replies

3. UNIX for Dummies Questions & Answers

Search and Count Occurrences of Pattern in a File

I need to search and count the occurrences of a pattern in a file. The catch here is it's a pattern and not a word ( not necessarily delimited by spaces). For eg. if ABCD is the pattern I need to search and count, it can come in all flavors like (ABCD, ABCD), XYZ.ABCD=100, XYZ.ABCD>=500,... (6 Replies)
Discussion started by: tektips
6 Replies

4. Shell Programming and Scripting

Search, group , print count

hi All, need help. have a file like below A, error in 123 B, log files are present A, error in 23444 B, log files are present A, move to next line C, matching messages -- expected output-- A , count =2 , error in * A , count =1 , move to next line B , count =2 , log files are present... (2 Replies)
Discussion started by: arun1401
2 Replies

5. Shell Programming and Scripting

Pattern search and count

Hi all, I need to search the database log find out the most frequently used tables for a certain period of time. The search pattern is : the database.table so, i need to look for ABCD.* in the entire log and then need the top ten tables. I thought of using awk, search for the pattern ... (7 Replies)
Discussion started by: ysvsr1
7 Replies

6. Shell Programming and Scripting

search and count

Hi, I have 2 files. file1: ABC 1160 1260 DEF 1360 1580 DEF 2300 2800 XYZ 1600 2200 file2: chr1_1000_1050 chr1_1100_1150 chr3_1151_1200 chr3_1201_1250 chr6_1301_1350 chr6_1351_1400 chr6_1550_1600 chrX_1600_1650 chrX_1851_1900 (8 Replies)
Discussion started by: Diya123
8 Replies

7. Shell Programming and Scripting

Search and count patterns

Hi, I have a text file the contents are like this now i want to search patterns Z , Z etc and count the occurrence of such patterns, after Z value can be any random digits, please help me it is urgent... output like this Z .............>5 Z ............>8 (9 Replies)
Discussion started by: sreejithalokkan
9 Replies

8. UNIX for Dummies Questions & Answers

How to search and count strings?

Hi, Is there a command to do a sensitive/in-sensitive search for a string on a line and print how many times that string appears? For example, if I have a line of text below: dog cat rat apple banana dog lion tiger dog Is there a command to search for dog that will print out 3 as a... (7 Replies)
Discussion started by: newbie_01
7 Replies

9. UNIX for Dummies Questions & Answers

Search and count a unique string

Hi Guys, I have a file as follows. Here is my story: For each field, the string in the 5th column needs to be searched in other fields of the same column and counted if the 1st column of the field is different from that of the primary field. BTW, the unique strings of 1st column need to be... (6 Replies)
Discussion started by: a_bahreini
6 Replies

10. Shell Programming and Scripting

awk variable search and line count between variable-search pattern

Input: |Running the Rsync|Sun Oct 16 22:48:01 BST 2016 |End of the Rsync|Sun Oct 16 22:49:54 BST 2016 |Running the Rsync|Sun Oct 16 22:54:01 BST 2016 |End of the Rsync|Sun Oct 16 22:55:45 BST 2016 |Running the Rsync|Sun Oct 16 23:00:02 BST 2016 |End of the Rsync|Sun Oct 16 23:01:44 BST 2016... (4 Replies)
Discussion started by: busyboy
4 Replies
LDAP_SEARCH(3)								 1							    LDAP_SEARCH(3)

ldap_search - Search LDAP tree

SYNOPSIS
resource ldap_search (resource $link_identifier, string $base_dn, string $filter, [array $attributes], [int $attrsonly], [int $size- limit], [int $timelimit], [int $deref]) DESCRIPTION
Performs the search for a specified filter on the directory with the scope of LDAP_SCOPE_SUBTREE. This is equivalent to searching the entire directory. From 4.0.5 on it's also possible to do parallel searches. To do this you use an array of link identifiers, rather than a single identi- fier, as the first argument. If you don't want the same base DN and the same filter for all the searches, you can also use an array of base DNs and/or an array of filters. Those arrays must be of the same size as the link identifier array since the first entries of the arrays are used for one search, the second entries are used for another, and so on. When doing parallel searches an array of search result identi- fiers is returned, except in case of error, then the entry corresponding to the search will be FALSE. This is very much like the value nor- mally returned, except that a result identifier is always returned when a search was made. There are some rare cases where the normal search returns FALSE while the parallel search returns an identifier. PARAMETERS
o $link_identifier - An LDAP link identifier, returned by ldap_connect(3). o $base_dn - The base DN for the directory. o $filter - The search filter can be simple or advanced, using boolean operators in the format described in the LDAP documentation (see the Netscape Directory SDK for full information on filters). o $attributes - An array of the required attributes, e.g. array("mail", "sn", "cn"). Note that the "dn" is always returned irrespective of which attributes types are requested. Using this parameter is much more efficient than the default action (which is to return all attributes and their associated values). The use of this parameter should therefore be considered good practice. o $attrsonly - Should be set to 1 if only attribute types are wanted. If set to 0 both attributes types and attribute values are fetched which is the default behaviour. o $sizelimit - Enables you to limit the count of entries fetched. Setting this to 0 means no limit. Note This parameter can NOT override server-side preset sizelimit. You can set it lower though. Some directory server hosts will be configured to return no more than a preset number of entries. If this occurs, the server will indicate that it has only returned a partial results set. This also occurs if you use this parameter to limit the count of fetched entries. o $timelimit - Sets the number of seconds how long is spend on the search. Setting this to 0 means no limit. Note This parameter can NOT override server-side preset timelimit. You can set it lower though. o $deref - Specifies how aliases should be handled during the search. It can be one of the following: o LDAP_DEREF_NEVER - (default) aliases are never dereferenced. o LDAP_DEREF_SEARCHING - aliases should be dereferenced during the search but not when locating the base object of the search. o LDAP_DEREF_FINDING - aliases should be dereferenced when locating the base object but not during the search. o LDAP_DEREF_ALWAYS - aliases should be dereferenced always. RETURN VALUES
Returns a search result identifier or FALSE on error. EXAMPLES
The example below retrieves the organizational unit, surname, given name and email address for all people in "My Company" where the sur- name or given name contains the substring $person. This example uses a boolean filter to tell the server to look for information in more than one attribute. Example #1 LDAP search <?php // $ds is a valid link identifier for a directory server // $person is all or part of a person's name, eg "Jo" $dn = "o=My Company, c=US"; $filter="(|(sn=$person*)(givenname=$person*))"; $justthese = array("ou", "sn", "givenname", "mail"); $sr=ldap_search($ds, $dn, $filter, $justthese); $info = ldap_get_entries($ds, $sr); echo $info["count"]." entries returned "; ?> PHP Documentation Group LDAP_SEARCH(3)
All times are GMT -4. The time now is 07:53 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy