Uniq sorting and count


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Uniq sorting and count
# 1  
Old 08-09-2011
Uniq sorting and count

Hi Unix gurus,

I have a requirement where I need to find the file count based on unique file names.
Code:
OPEN_INV_MMDDYYYY_HHMM.xls
OPEN_INV_MMDDYYYY_HHMM.xls
OPEN_INV_MMDDYYYY_HHMM.xls

CLOSE_INV_MMDDYYYY_HHMM.xls
CLOSE_INV_MMDDYYYY_HHMM.xls

OPEN_INV_MMDDYYYY_HHMM.txt
OPEN_INV_MMDDYYYY_HHMM.txt

The file count should be:
Code:
3
2
2

The uniqueness in the filenames will be based on file extensions and any characters before "_MMDDYYYY_HHMM.extension"

I am doing something like this:
Code:
for archpref in $(ls | sed 's/[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]\.[^.]*$//' | sort | uniq)
do 
  archive_file_count=$(ls -1t ${archpref}*  | wc -l)
  echo archcnt: $archive_file_count
done

Right now I get the archcnt as
Code:
1
1
1
1
1
1
1

Please help me !!!!!


Thanks
Shankar

Moderator's Comments:
Mod Comment Please use code tags. Thank you.

Last edited by Scott; 08-09-2011 at 01:02 PM.. Reason: Code tags
# 2  
Old 08-09-2011
For starters, your sed regular expression does not match the pattern in your sample data. It attempts to match 8 digits followed by a dot followed by not-dot until the end of line (the file extension). However, your sample data shows 8 digits followed by an underscore and four more digits before the dot that delimits the file extension.

Regards,
Alister
# 3  
Old 08-09-2011
Alister,

Can you please help me to change the command?

Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to find the count of IP addresses that belong to different subnets and display the count?

Hi, I have a file with a list of bunch of IP addresses from different VLAN's . I am trying to find the list the number of each vlan occurence in the output Here is how my file looks like 1.1.1.1 1.1.1.2 1.1.1.3 1.1.2.1 1.1.2.2 1.1.3.1 1.1.3.2 1.1.3.3 1.1.3.4 So what I am trying... (2 Replies)
Discussion started by: new2prog
2 Replies

2. Shell Programming and Scripting

Uniq count second column

Hello How can I get a number of occurrence count for this file; ERR315389.1000156 CTTGAAGAAGAATTGAAAACTGTGACGAACAACTTGAAGTCACTGGAGGCTCAGGCTGAGAAGTACTCGCAGAAGGAAGACAGATATGAGGAAGAG ERR315389.1000281 ... (3 Replies)
Discussion started by: Wan Fahmi
3 Replies

3. Shell Programming and Scripting

Count occurences of a character in a file by sorting results

Hello, I try to sort results of occurences in an array by using awk but I can't find the right command. that's why I'm asking your help ! :) Please see below the command that I run: awk '{ for ( i=1; i<=length; i++ ) arr++ }END{ for ( i in arr ) { print i, arr } }' dictionnary.txt ... (3 Replies)
Discussion started by: destin45
3 Replies

4. Shell Programming and Scripting

Compare file1 header count with file2 line count

What I'm trying to accomplish. I receive a Header and Detail file for daily processing. The detail file comes first which holds data, the header is a receipt of the detail file and has the detail files record count. Before processing the detail file I would like to put a wrapper around another... (4 Replies)
Discussion started by: pone2332
4 Replies

5. Shell Programming and Scripting

awk - getting uniq count on multiple col

Hi My file have 7 column, FIle is pipe delimed Col1|Col2|col3|Col4|col5|Col6|Col7 I want to find out uniq record count on col3, col4 and col2 ( same order) how can I achieve it. ex 1|3|A|V|C|1|1 1|3|A|V|C|1|1 1|4|A|V|C|1|1 Output should be FREQ|A|V|3|2 FREQ|A|V|4|1 Here... (5 Replies)
Discussion started by: sanranad
5 Replies

6. Shell Programming and Scripting

Sorting user by last login an count

Experts need your help i need to create a script which will give count of users logged between yesterday and today (Or if run exacle 12:00AM midnight, it will give count of of users logged on that day here is how the data looks Pappu, Paul|22-Feb-201|0|30-Jun-201 Aloor,... (9 Replies)
Discussion started by: karghum
9 Replies

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

8. UNIX for Dummies Questions & Answers

Difference between plain "uniq" and "uniq -u"

Dear all, It's not entirely clear to me from manpage the difference between them. Why we still need "-u" flag? - monkfan (3 Replies)
Discussion started by: monkfan
3 Replies

9. UNIX for Dummies Questions & Answers

Sorting using count, grep and count

Hi, I trying to sort information in a file by making count for every object. For example: A B A D A B C i would like to sort out count for each object (A's, B's and etc) but in actual case i dont know the object but i know the position ofthe object. do i need to use array as well? Any... (2 Replies)
Discussion started by: sukhpal_78
2 Replies
Login or Register to Ask a Question