The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Problem with GREP. syndex Shell Programming and Scripting 2 07-11-2007 10:44 AM
grep problem asal_email2 UNIX for Dummies Questions & Answers 4 06-22-2005 05:49 PM
grep problem svennie UNIX for Dummies Questions & Answers 5 11-08-2004 01:29 AM
Grep Problem lesstjm Shell Programming and Scripting 2 10-27-2004 07:13 AM
Grep problem odogbolu98 Shell Programming and Scripting 3 02-18-2003 12:53 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 11-09-2006
yogesh_powar's Avatar
Registered User
 

Join Date: Jun 2005
Location: satara
Posts: 37
Question grep problem

Code:
cat *:22:B0
has the following output
Code:
2220 -50
2220 -50
2220 -51
2225 -47
2225 -50
2230 -63
2230 -50
2235 -50
2235 -50
2235 -48
2240 -53
2240 -53
2245 -51
2245 -51
2250 -52
2250 -52
2250 -50
Code:
#!/bin/bash

#All unique numbers from file *:22:B0 will be in /tmp/uni
cat *:22:B0|awk  '{print $2}'|sort -nu>>/tmp/uni


# max will number of unique numbers
max=wc -l /tmp/uni |awk '{print $1}'

for((i=1;i<$max;i++))
        do

# pattern will have each unique number
    pattern=`cat /tmp/uni|head -$i|tail -1`


#Following code should find out how many occurance of pattern are there in *:22:B0
        cat *:22:B0|grep $pattern|wc -l


        done
There is some syntax wrong in last line.
what is wrong?
Reply With Quote
Forum Sponsor
  #2  
Old 11-09-2006
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,014
wouldn't it be easier to do it all in awk?
Code:
nawk '{arr[$2]++} END {for (i in arr) printf("pattern->[%s] numOFoccur->[%d]\n", i, arr[i])}' *:22:B0
Reply With Quote
  #3  
Old 11-09-2006
yogesh_powar's Avatar
Registered User
 

Join Date: Jun 2005
Location: satara
Posts: 37
thanks

thanks you very much.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 07:49 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0