search and count


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users search and count
# 1  
Old 02-04-2009
Question search and count

Hi,

I would like to seek help regarding searching a pattern on a particular input.

Example input:
"1|trunc(sysdate-1)|substring(pcol)"

I would like to search for "|" and count it.

any help will be much appreciated.

Thanks! Smilie
Newbie
# 2  
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...
# 3  
Old 02-09-2009
MySQL

Use awk...

echo "1|trunc(sysdate-1)|substring(pcol)" | awk -F "|" '{print NF-1}'
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

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

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

10. 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
Login or Register to Ask a Question