The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Awk to count matching IP address new_buddy Shell Programming and Scripting 3 05-28-2008 05:24 AM
nawk-how count the number of occurances of a pattern, when don't know the pattern cyber111 Shell Programming and Scripting 2 05-11-2008 03:00 AM
finding duplicate files by size and finding pattern matching and its count jerome Sukumar Shell Programming and Scripting 2 12-01-2006 04:20 AM
Pattern matching sed leemjesse Shell Programming and Scripting 3 03-23-2005 04:06 AM
pattern matching larryase UNIX for Dummies Questions & Answers 3 11-22-2004 06:54 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-30-2008
krabu krabu is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 44
Question Pattern Matching Count Urgent

The input is like

NO Code
030019991 22
030087819 0
030089001 22
030178901 39
030333333 22

Patterns i want to match is 0300 0301 0303. i want to count different Codes occurances for each of these pattern. for example for 0300 Code 22 occurs 2 times and 0 occurs 1 time. output should be like that

300:
22 2
0 1
0301:
39 1 etc
I have large no of patterns so i have to save them in array and then match them . Please can someone provide with the shell script urgently.
  #2 (permalink)  
Old 07-30-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Wink Perhaps a start

The following is based on the small sample file provided:

Code:
> cat patt_file | cut -c1-4,10-12 | sort | uniq -c
      1 0300 0
      2 0300 22
      1 0301 39
      1 0303 22
You might need to play with the layout, but the output is
count pattern code
  #3 (permalink)  
Old 07-30-2008
krabu krabu is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 44
Works But

Quote:
Originally Posted by joeyg View Post
The following is based on the small sample file provided:

Code:
> cat patt_file | cut -c1-4,10-12 | sort | uniq -c
      1 0300 0
      2 0300 22
      1 0301 39
      1 0303 22
You might need to play with the layout, but the output is
count pattern code
it works fine but matching Patterns may not be 4 digit in lenght that may be 2,5 or 7 etc. Alse file is csv and much more colums may be present between code 22 etc and No 0300... . I will much appreciate your help
  #4 (permalink)  
Old 07-30-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Question If file is csv, then perhaps easier

Can you include a sample of the datafile? Perhaps first ten lines or so?

Since you say csv, then you can cut by field rather than character positions - thereby addressing your concern about field length.
  #5 (permalink)  
Old 07-31-2008
krabu krabu is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 44
Another Problem

Quote:
Originally Posted by joeyg View Post
Can you include a sample of the datafile? Perhaps first ten lines or so?

Since you say csv, then you can cut by field rather than character positions - thereby addressing your concern about field length.
i have written the script in cshell but there is another problem that when define variables in a file then run the file error ocurrs something like
missing )
e:g >>cat abc
set a =0;
set xyz =(1 2 3 4 5 6);
>> chmod 777 abc;
>>abc
missing parameter )
how can i correct this. I will much appreciate your help.
  #6 (permalink)  
Old 07-31-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,715
You are not defining 'pattern' - you gave an example of four digits out of eight at the start of a line.

Assuming the first column is a pattern - any combination of digits/letters:
Code:
awk '{ arr[$1]++ }
       END { for (i in arr) { print i, arr[i]} } ' filename
  #7 (permalink)  
Old 07-31-2008
krabu krabu is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 44
How to define variables in a file

ok thnk

Last edited by krabu; 10-10-2008 at 03:00 AM..
Sponsored Links
Closed Thread

Bookmarks

Tags
sort, uniq

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:54 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0