![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
| Counting files in one directory | matrixtlm | UNIX for Dummies Questions & Answers | 10 | 06-15-2007 07:14 PM |
| Counting number of files in a directory | iamalex | UNIX for Dummies Questions & Answers | 2 | 09-05-2005 10:13 AM |
| List files that do not match the search pattern | olapxpert | UNIX for Dummies Questions & Answers | 7 | 04-14-2005 03:49 PM |
| List files that do not match the search pattern | olapxpert | IP Networking | 1 | 04-14-2005 02:37 PM |
| rm files in a directory, looping, counting, then exit | JporterFDX | Shell Programming and Scripting | 6 | 07-18-2002 08:56 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Counting files in a directory that match a pattern
I have 20 files in a direcotry like BARE01_DLY_MKT_YYYYMMDD. The MKT differes for all these files but the remaining syntax remains the same for a particular day. If I am checking for today I need to make sure that there are 20 files that start with BARE01_DLY_MKT_20060720. How can I write a shell script to do this? I think I have to use for loop but don't know how to check for today or not. Kindly help.
|
|
||||
|
Pierre,
Do you mean i have to have the code like this: integer filecount=0 for file in BARE01_DLY_???_$(date +%Y%m%d); do filecount=$filecount+1 done echo $filecount if (( $filecount == 20 )); then print "True" else print "False" fi is this right? How can i embed them in the single KSH script. Please let me know. |
|
|||||
|
I don't know what you expect as output. Without knowing all your requirements (and without having a desire to write the entire script for you), I would do:
check20.sh: Code:
#!/bin/ksh integer filecount=0 for file in BARE01_DLY_???_$(date +%Y%m%d); do filecount=$filecount+1 done if (( $filecount == 20 )); then exit 0 # exit with success else exit 1 # exit with failure fi |
|
||||
|
Glenn,
I am sorry if I had asked to mean to write a script. But I created the script with the statements. What I need to know is I need to pass the name of the file as a parameter to the script and then do the processing we had before. How can this be possible. The name of the files will look like BARE01_DLY_MKT_yyyymmdd for 20 markets. This script need to work for files named BARE02_DLY_MKT_20060803 which will be 20 again. So I need to generalise the script and pass the name of the file as parameter. So how can acheive this. Please let me know. I am trying to learn and develop at the same time. Once again I appreicate your knid response. |
|
|||||
|
You're checking to see if 20 files named using the form, "BARE01_DLY_MKT_yyyymmdd" (where "MKT" is variable between all 20 files). How would passing one file name to the script help? Unless you mean to pass the date to the script so that it checks for that date? That is, today's date is 20060720, but you want to check for 20 files with the date 20060719...?
check20.sh 20060803: Code:
#!/bin/ksh mydate=$1 integer filecount=0 for file in BARE01_DLY_???_$mydate; do filecount=$filecount+1 done if (( $filecount == 20 )); then exit 0 else exit 1 fi |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|