List files only when a certain number of files match


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting List files only when a certain number of files match
# 1  
Old 07-20-2011
List files only when a certain number of files match

Hi,
I have many files named CCR20110720011001.CTRD
CCR20110720011501.CTRD
CCR20110720012001.CTRD
CCR20110720012501.CTRD
CCR20110720021001.CTRD
CCR20110720021501.CTRD
CCR20110720022001.CTRD
.
.
.
.
.
i put the part of date in variable (DATE=20110720)

NB : Red=date, Green=hour, blue=minute

and i want to do somthing like that :

Code:
i=1
while [ $i -lt 10 ]
do
nb=`ls -l *$(DATE)0$i`
    if [ $nb -lt 12 ]
    then
         ls -l *$(DATE)0$i
    fi
i=`expr $i + 1`
done


objective : list all the hours wich contains a numbre of file less then 12

this part doesn't works : nb=`ls -l *$(DATE)0$i`
the script list all the files !! it don't understand $(DATE)0$i

Please if sombody can Help me.
# 2  
Old 07-20-2011
Hello,

Per our forum rules, all threads must have a descriptive subject text. For example, do not post questions with subjects like "Help Me!", "Urgent!!" or "Doubt". Post subjects like "Execution Problems with Cron" or "Help with Backup Shell Script".

The reason for this is that nearly 95% of all visitors to this site come here because they are referred by a search engine. In order for future searches on your post (with answers) to work well, the subject field must be something useful and related to the problem!

In addition, current forum users who are kind enough to answer questions should be able to understand the essence of your query at first glance.

So, as a benefit and courtesy to current and future knowledge seekers, please be careful with your subject text. You might receive a forum infraction if you don't pay attention to this.

Thank you.

The UNIX and Linux Forums
# 3  
Old 07-20-2011
$DATE isn't defined in that part of the code. If all are listed, that will not be necessarily wrong, if I understood it correct, since all green numbers of your example are less than 12.

Code:
$> ls -1
CCR20110720011001.CTRD
CCR20110720011501.CTRD
CCR20110720012001.CTRD
CCR20110720021001.CTRD
CCR20110720021501.CTRD
CCR20110720142001.CTRD
CCR20110720152501.CTRD
$> ls *CTRD| grep .*0[1-9]....\.CTRD
CCR20110720011001.CTRD
CCR20110720011501.CTRD
CCR20110720012001.CTRD
CCR20110720021001.CTRD
CCR20110720021501.CTRD

# 4  
Old 07-20-2011
My bad, I just did only 1-10, not 1-12, so here you go:

Code:
ls *CTRD| grep -E ".*(0[1-9]|1[0-1])....\.CTRD"

# 5  
Old 07-20-2011
thanks zaxxon for your quick answer.
i going to explain more to understand me well
we receive 12 file in the hour.
i want to list just the files from the 01 hour to 10 which the number of this files less than 12. i'm interested just by the first 10 hours.

Thanks
# 6  
Old 07-20-2011
I am still not sure, sorry.

What I understood:
  • You get 12 files per hour.
  • You only want to list files that came from hour 01 to 10.

What I do not understand is:
Quote:
which the number of this files less than 12
So the 12 files per hour is fix and if there is 1 or more less than 12, in other words there is missing some of them, you want to see those, that have arrived, right?
# 7  
Old 07-20-2011
Yu could try this:

Where i have a text file called hours.txt with:

Code:
CCR20110720011501.CTRD
CCR20110720012001.CTRD
CCR20110720012501.CTRD
CCR20110720021001.CTRD
CCR20110720021501.CTRD
CCR20110720022001.CTRD
CCR20110720032001.CTRD
CCR20110720032501.CTRD
CCR20110720032601.CTRD
CCR20110720032701.CTRD
CCR20110720032801.CTRD
CCR20110720032801.CTRD
CCR20110720102801.CTRD
CCR20110720113001.CTRD

This line:
Code:
sed 's/^[A-Z]..........\(0[1-9]\|1[0]\).*/\1/g' hours.txt |sed '/^C.*/d'| awk '{gsub(/CCR20110720/,"",$1); gsub(/.....CTRD/,"",$1); print}' hours.txt | sort |uniq -c |awk 'BEGIN { print "OCURRENCES  HOUR"; print "----  -----"} { if ($1 < 5 && $2 <= 10){ print $1 "\t"$2 }}'

Output is:
Code:
OCURRENCES  HOUR
----  -----
3       01
3       02
1       10

Am sure there's a shorter way Smilie

Last edited by maskofzorro; 07-20-2011 at 12:06 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Count the number of files to delete doesnt match

Good evening, need your help please Need to delete certain files before octobre 1 2016, so need to know how many files im going to delete, for instance ls -lrt file_20160*.lis!wc -l but using grep -c to another file called bplist which contains the list of all files backed up doesn match... (7 Replies)
Discussion started by: alexcol
7 Replies

2. Shell Programming and Scripting

List files with number to select based on number

Hi experts, I am using KSH and I am need to display file with number in front of file names and user can select it by entering the number. I am trying to use following command to display list with numbers. but I do not know how to capture number and identify what file it is to be used for... (5 Replies)
Discussion started by: mysocks
5 Replies

3. Shell Programming and Scripting

Rename files to match file list pattern

Hi All, I have 100 folders with the first delimiter has a unique name i.e (123_hello and 575_hello) and each folder have atlist 1000 plus files with naming convention i.e (575_hello_1.iso ... 575_hello_1000.iso). 575_hello/575_hello_1.iso 575_hello/575_hello_2.iso 575_hello/575_hello_3.iso... (8 Replies)
Discussion started by: lxdorney
8 Replies

4. Shell Programming and Scripting

Finding log files that match number pattern

I have logs files which are generated each day depending on how many processes are running. Some days it could spin up 30 processes. Other days it could spin up 50. The log files all have the same pattern with the number being the different factor. e.g. LOG_FILE_1.log LOG_FILE_2.log etc etc ... (2 Replies)
Discussion started by: atelford
2 Replies

5. Shell Programming and Scripting

Match number from 2 input files

I have 2 input files; file1: 1 1000 2000 x1 1 5000 7000 x5 1 8000 10000 x8 file2: 1 1000 x1 z1 2 1001 x2 z2 1 1999 x3 z3 2 2000 x4 z4 1 2001 x5 z5 1 2002 x6 z6 1 6100 x7 z7 1 6200 x8 z8 1 7500 x9 z9 2 8500 x10 z10 I want to get the output look like this (1 Reply)
Discussion started by: akenaza
1 Replies

6. Shell Programming and Scripting

grep - match files containing minimum number of pattern matches

I want to search a bunch of files and list only those containing a minimum number of pattern matches. So if I want to identify files containing 3 (or more) instances of the pattern "said:" and I have file1 that contains the lines: He said: She said: and file2 that contains the lines: He... (3 Replies)
Discussion started by: stumpyuk
3 Replies

7. UNIX for Dummies Questions & Answers

How to list number of files through Crontab?

Hello All, I am trying to put this line in Crontab (Linux box- x86_64), but the command is not running. Can you please help me out? My requirement is- To find out the number of .csv files older than 1 day in directory /stage/landing. There are 2 other subdirectories under this directory... (6 Replies)
Discussion started by: NARESH1302
6 Replies

8. UNIX for Dummies Questions & Answers

Comparing two files and count number of lines that match

Hello all, I always found help for my problems using the search option, but this time my request is too specific. I have two files that I want to compare. File1 is the index and File2 contains the data: File1: chr1 protein_coding exon 500 600 . + . gene_id "20532";... (0 Replies)
Discussion started by: DerSeb
0 Replies

9. UNIX for Dummies Questions & Answers

List files that do not match the search pattern

I need to list the files that do not match the search pattern: Example: cat file1 This is how it should work cat file2 This is why I like Unix grep -option? Unix * (or some other command) returns file1 (7 Replies)
Discussion started by: olapxpert
7 Replies

10. IP Networking

List files that do not match the search pattern

I need to list the files that do not match the search pattern: Example: cat file1 This is how it should work cat file2 This is why I like Unix grep -option? Unix * (or some other command) returns file1 (1 Reply)
Discussion started by: olapxpert
1 Replies
Login or Register to Ask a Question