How to count a string only if has a particular string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to count a string only if has a particular string
# 1  
Old 05-27-2008
How to count a string only if has a particular string

Hi,

I have a file which has the contents as like below,

10:22:23 Good 10.20.30.40
10:22:23 Good 10.20.30.41
10:22:23 Good 10.20.30.55
10:22:23 Hello 10.20.30.40
10:22:23 Bad 10.20.30.40
10:22:23 Hello 10.20.30.41
10:22:23 Hello 10.20.30.41
10:22:23 Bad 10.20.30.41
10:22:23 Bad 10.20.30.55

I need the output like this,

Number of Good-Bad has Hello string inbetween them

(account Good-bad based on the ip in the 3rd column)

For the above file output should be like,

Number of Good-Bad has Hello string: 2

Number of Good-Bad without Hello String :1

Please suggest a script for this....

Thanks in advance,
# 2  
Old 05-27-2008
No duplicate or cross-posting, read the rules.

This a similar question of:

https://www.unix.com/shell-programmin...n-matches.html

Thread closed.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep a string and count following lines starting with another string

I have a large dataset with following structure; C 0001 Carbon D SAR001 methane D SAR002 ethane D SAR003 propane D SAR004 butane D SAR005 pentane C 0002 Hydrogen C 0003 Nitrogen C 0004 Oxygen D SAR011 ozone D SAR012 super oxide C 0005 Sulphur D SAR013... (3 Replies)
Discussion started by: Syeda Sumayya
3 Replies

2. Shell Programming and Scripting

Count percentage of string

Hi, Am trying to count the number of occurrences and then as a percentage from a log to troubleshoot errors, can someone help please grep -o 'HTTP/1\.1\" 404 3..' access_log | wc -l 6 (5 Replies)
Discussion started by: dmccabe
5 Replies

3. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

4. Shell Programming and Scripting

how to count string length?

Hi, Gurus, I have a requirement which need count string length. eg. abc bcde defge want to get following: abc 3 bcde 4 defge 5 :wall: thanks in advance! (6 Replies)
Discussion started by: ken002
6 Replies

5. Shell Programming and Scripting

Count occurences of string

Hi, Please help me in finding the number of occurences of the string. Example: Apple, green, blue, Apple, Orange, green, blue are the strings can be even in the next line. The o/p should look as: Word Count ----- ----- Apple 2 green 2 Orange 1 blue 2 Thanks (2 Replies)
Discussion started by: acc888
2 Replies

6. Shell Programming and Scripting

To count a string with in a variable

I am writing a ksh to check for duplicate records in two different set of tables on oracle database, to get this i am running two plsql qurries at a time through the ksh, so the output of the qurries will be stored in variable say "SQL_STRING". So now to say if duplicate records exists in table or... (6 Replies)
Discussion started by: vpv0002
6 Replies

7. Shell Programming and Scripting

count of a string within a variable

I am writing ksh to check for duplicate records in two different set of tables on oracle database, to get this i am running two plsql qurries at a time through the ksh, so the output of the qurries will be stored in variable say "SQL_STRING". So now to say if duplicate records exists in table or... (3 Replies)
Discussion started by: vpv0002
3 Replies

8. UNIX for Dummies Questions & Answers

Count the characters in a string

Hi all, I like to know how to get the count of each character in a given word. Using the commands i can easily get the output. How do it without using the commands ( in shell programming or any programming) if you give outline of the program ( pseudo code ) i used the following commands ... (3 Replies)
Discussion started by: itkamaraj
3 Replies

9. Shell Programming and Scripting

count times for one string

I have a file. I want to count the time for one string appears in this file Example: 56 73 34 79 90 56 34 Expected results 2:56 1:73 2:34 (1 Reply)
Discussion started by: anhtt
1 Replies

10. Shell Programming and Scripting

Count string at header.

Hi there, it may quite easy but i've tried my best to editing this awk script but didn't get to solution. Scripts:BEGIN { Header = "1 "; FileType = "NBI"; #Count = Count + 1; printf("%-2s%-3s%03s%-14s%-84s\r\n", Header, FileType, Count, FileSeq, SysTime, " "); } { ... (13 Replies)
Discussion started by: Helmi
13 Replies
Login or Register to Ask a Question