Search, group , print count

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Search, group , print count
# 1  
Old 07-22-2011
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
C , count =1 , matching messages

if pattern is always same, sort | uniq -c will help ..
but when patterns differ for few words - want to pick matching content and ignore unmatched , want a count on them.. not getting a clue on how to start/ where to start
# 2  
Old 07-23-2011
open I, "$ARGV[0]";
while (<I>){
  /^(\w+, \w+)/;
  if (!$l{$m}){
    @x=split //;
    @y=split //, $l{$m};
    for ($i=0;$i<=$#y;$i++){
      if ($y[$i] eq $x[$i]){
for (keys %c){
  print "$1 , count =$c{$_} $l{$_}\n";

Run this script as: ./ file
# 3  
Old 07-23-2011
Maybe this will be enough?

% sort INPUTFILE | uniq -c -w 10
      2 A, error in 123
      1 A, move to next line
      2 B, log files are present
      1 C, matching messages

If you need more specific output, you can make it with awk or perl.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Search for Multiple strings in a given date range and print the Group if they exists

Hi, I am Searching for Multiple strings in a given date range and print the Group if they exists. the below is the format: ------------------------------------------------------------------------------------------------------------------------- ID: FIRST ID MESSAGE: Event Message... (5 Replies)
Discussion started by: linuxuser999
5 Replies

2. Shell Programming and Scripting

awk Group By and count string occurrences

Hi Gurus, I'm scratching my head over and over and couldn't find the the right way to compose this AWK properly - PLEASE HELP :confused: Input: c,d,e,CLICK a,b,c,CLICK a,b,c,CONV c,d,e,CLICK a,b,c,CLICK a,b,c,CLICK a,b,c,CONV b,c,d,CLICK c,d,e,CLICK c,d,e,CLICK b,c,d,CONV... (6 Replies)
Discussion started by: Royi
6 Replies

3. Shell Programming and Scripting

need a one liner to grep a group info from /etc/group and use that result to search passwd file

/etc/group tiadm::345:mk789,po312,jo343,ju454,ko453,yx879,iy345,hn453 bin::2:root,daemon sys::3:root,bin,adm adm::4:root,daemon uucp::5:root /etc/passwd mk789:x:234:1::/export/home/dummy:/bin/sh po312:x:234:1::/export/home/dummy:/bin/sh ju454:x:234:1::/export/home/dummy:/bin/sh... (6 Replies)
Discussion started by: chidori
6 Replies

4. Shell Programming and Scripting

Sort the file contents in each group....print the group title as well

I've this file and need to sort the data in each group File would look like this ... cat file1.txt Reason : ABC 12345-0023 32123-5400 32442-5333 Reason : DEF 42523-3453 23345-3311 Reason : HIJ 454553-0001 I would like to sort each group on the last 4 fileds and print them... (11 Replies)
Discussion started by: prash184u
11 Replies

5. Shell Programming and Scripting

split file based on group count

Hi, can some one please help me to split the file based on groups. like in the below scenario x indicates the begining of the group and the file should be split each with 2 groups below there are 10 groups it should create 5 files. could you please help? (4 Replies)
Discussion started by: hitmansilentass
4 Replies

6. Shell Programming and Scripting

count identical strings print last row and count

I have a sorted file like: Apple 3 Apple 5 Apple 8 Banana 2 Banana 3 Grape 31 Orange 7 Orange 13 I'd like to search $1 and if $1 is not the same as $1 in the previous row print that row and print the number of times $1 was found. so the output would look like: Apple 8 3 Banana... (2 Replies)
Discussion started by: dcfargo
2 Replies

7. UNIX for Dummies Questions & Answers

Grep group by and count

Hi, I have several files with same filename pattern. I want to calculate count of individual files using grep/egrep. Let me be more descriptive In directory E1 i have files like ab_20091201_12:24 ab_20091201_03:24 cd_20091201_04:16 cd_20091203_08:34 ef_20091201_06:12 ef_20091201 Now i want... (3 Replies)
Discussion started by: shounakboss
3 Replies

8. Shell Programming and Scripting

Group and count file by date

Hi all, in BIN/SH I need to group and count files by date. Ie: ls -la -rw-r--r-- 1 aaa dba 122 Jul 13 14:28 as1.tmp -rw-r--r-- 1 aaa dba 122 Jul 13 15:27 as2.tmp -rw-r--r-- 1 aaa dba 122 Jul 21 17:04 as3.tmp -rw-r--r-- 1 aaa dba 122 Jul 23 15:45 as4.tmp -rw-r--r-- 1 aaa... (8 Replies)
Discussion started by: ric79
8 Replies

9. Shell Programming and Scripting

Awk-Group count of field

Hi, Suppose if i am having a file with following records as given below. 5555 6756 5555 4555 4555 6767 how can i get the count of each record using AWK. Eg:5555 count should be 2 4555 count should be 2 6767 count should be 1 ... (5 Replies)
Discussion started by: tinivt
5 Replies

10. Shell Programming and Scripting

awk help required to group output and print a part of group line and original line

Hi, Need awk help to group and print lines to format the output as shown below INPUT FORMAT set echo on set heading on set spool on /* SCHEMA1 */ CREATE TABLE T1; /* SCHEMA1 */ CREATE TABLE T2; /* SCHEMA1 */ CREATE TABLE T3; /* SCHEMA1 */ CREATE TABLE T4; /* SCHEMA1 */ CREATE TABLE T5;... (5 Replies)
Discussion started by: rajan_san
5 Replies
Login or Register to Ask a Question