Sponsored Content
Top Forums Shell Programming and Scripting Counting files in a directory that match a pattern Post 302080764 by Glenn Arndt on Thursday 20th of July 2006 12:02:55 PM
Old 07-20-2006
Using ksh:
Code:
integer filecount=0
for file in BARE01_DLY_???_$(date +%Y%m%d); do
  filecount=$filecount+1
done
echo $filecount

Your test could look something like:
Code:
if (( $filecount == 20 )); then
  print "True"
else
  print "False"
fi


Last edited by Glenn Arndt; 07-20-2006 at 01:06 PM.. Reason: Didn't include an example test
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

rm files in a directory, looping, counting, then exit

I am trying to write a script that will look for a file in a directory, then remove it. I need it to loop until it has removed a certain number of files. Is it better to do a repeat or to list each file in a pattern? Files will be numbered like RAF.01.*, RAF.02.*, etc. Thanks, James (6 Replies)
Discussion started by: JporterFDX
6 Replies

2. UNIX for Dummies Questions & Answers

Counting number of files in a directory

Some simple questions from a simple man. If i wanted to count the number of files contained within a directory, say /tmp would ls -l /tmp ¦ wc -l suffice and will it be accurate? second one: How would i check the number of files with a certain string in the filename, in the same directory. ... (2 Replies)
Discussion started by: iamalex
2 Replies

3. UNIX for Dummies Questions & Answers

copying a pattern of files in one directory into other with new pattern names...

Hi, I have to copy a set of files abc* in /path/ to /path1/ as abc*_bkp. The list of files appear as follows in /path/: abc1 xyszd abc2 re2345 abcx .. . abcxyz I have to copy them (abc* files only) into /path1/ as: abc1_bkp abc2_bkp abcx_bkp .. . (6 Replies)
Discussion started by: new_learner
6 Replies

4. Shell Programming and Scripting

pattern search for multiple log files and counting

I have 10 appservers and each appserver has 4 jvms . Each of these logs is archived and stored on a nfs directory . For example the files are /logs/200907/ap1-jvm1.server.log.20090715.gz /logs/200907/ap2-jvm2.server.log.20090714.gz /logs/200908/ap1-jvm1.server.log.20090812.gz I want to... (3 Replies)
Discussion started by: gubbu
3 Replies

5. UNIX for Advanced & Expert Users

Counting files in a given directory

Hi all, Need some help counting files... :) I'm trying to count the number of files in a given directory (and subdirectories) which reportedly contains "thousands" of files. I'm using this: ls -R | wc -l However it's been an hour and looks like it's still running; there is no output... (18 Replies)
Discussion started by: verdepollo
18 Replies

6. Shell Programming and Scripting

counting the number of characters in the filename of all files in a directory?

I am trying to display the output of ls and also print the number of characters in EVERY file name. This is what I have so far: #!/bin/sh for x in `ls`; do echo The number of characters in x | wc -m done Any help appreciated (1 Reply)
Discussion started by: LinuxNubBrah
1 Replies

7. Shell Programming and Scripting

Counting the number of files within a directory input by the user

So I have a loop that stated if a directory exists or not. If it does it prints the number of files within that directory. I use this code... result=`(ls -l . | egrep -c '^-')` However, no matter which directory I input, it outputs the number "2" What is wrong here? (4 Replies)
Discussion started by: itech4814
4 Replies

8. Shell Programming and Scripting

counting lines that match pattern

I have a file of 1.3 millions lines. some are with the same word twice on the line, some line have two diffrent words. each line has two words, one in brackets. example: foo (foo) bar (bar) thae (awvd) beladf (vswvw) I am sure this can be done with one line of... (6 Replies)
Discussion started by: robsonde
6 Replies

9. Shell Programming and Scripting

Rearrange or replace only the second line after pattern match or pattern match

Im using the command below , but thats not the output that i want. it only prints the odd and even numbers. awk '{if(NR%2){print $0 > "1"}else{print $0 > "2"}}' Im hoping for something like this file1: Text hi this is just a test text1 text2 text3 text4 text5 text6 Text hi... (2 Replies)
Discussion started by: invinzin21
2 Replies

10. Shell Programming and Scripting

Pattern match and replace indirect directory reference using sed

Hi, I need a ksh script to replace indirect directory references in an .ini file with a env variable using sed or awk. The .ini file is for example as such: A=.. B=../ C=../.. D=../../ E=../bin F=../../bin G=../../bin/xml H=../../bin/xml/ Need to replace an instance of .. or... (2 Replies)
Discussion started by: andyatit
2 Replies
SLOCCOUNT(1)							     SLOCCount							      SLOCCOUNT(1)

NAME
sloccount - count source lines of code (SLOC) SYNOPSIS
sloccount [--version] [--cached] [--append] [ --datadir directory ] [--follow] [--duplicates] [--crossdups] [--autogen] [--multiproject] [--filecount] [--wide] [--details] [ --effort F E ] [ --schedule F E ] [ --personcost cost ] [ --overhead overhead ] [ --addlang language ] [ --addlangall ] [--] directories DESCRIPTION
sloccount counts the physical source lines of code (SLOC) contained in descendants of the specified set of directories. It automatically determines which files are source code files, and it automatically determines the computer language used in each file. By default it sum- marizes the SLOC results and presents various estimates (such as effort and cost to develop), but its output can be controlled by various options. If you give sloccount a list of two or more directories, the counts will be broken up according to that list. There is one important limi- tation: the basenames of the directories given as parameters must be different, because those names are used to group summary information. Thus, you can't run "sloccount /usr/src/hello /usr/local/src/hello". This limitation only applies to parameters of sloccount - subdirecto- ries descended from the top directories can have the same basename. If you give sloccount only a single directory, sloccount tries to automatically find a reasonable breakdown for purposes of reporting (so it'll produce a useful report). In this case, if the directory has at least two subdirectories, then those subdirectories will be used as the breakdown. If the single directory contains files as well as directories (or if you give sloccount some files as parameters), those files will be assigned to the directory "top_dir" so you can tell them apart from other contents. Finally, if there's a subdirectory named "src", then that subdirectory is again broken down, with all the further subdirectories prefixed with "src_". Thus, if directory "X" has a subdirectory "src", which contains subdirectory "modules", sloccount will report a separate count for "src_modules". sloccount normally considers all descendants of these directories, though unless told otherwise it ignores symbolic links. sloccount is the usual front-end of the package of tools named "SLOCCount". Note that the name of the entire package has capital letters, while the name of this front-end program does not. sloccount will normally report estimates of schedule time, effort, and cost, and for single projects it also estimates the average number of active developers. These are merely estimates, not etched in stone; you can modify the parameters used to improve the estimates. OPTIONS
--version Report the version number of SLOCCount and immediately exit. This option can't be usefully combined with any other option. --cached Do not recalculate; instead, use cached results from a previous execution. Without the --cached or --append option, sloccount automatically removes the data directory and recreates it. --append Do not remove previous calculations from the data directory; instead, add the analysis to the current contents of the data directory. --datadir directory Store or use cached data in the given data directory; default value is "~/.slocdata". --follow Follow symbolic links. --duplicates Count all duplicates. Normally, if files have equal content (as determined using MD5 hash values), only one is counted. --crossdups Count duplicates if they occur in different portions of the breakdown. Thus, if the top directory contains many different projects, and you want the duplicates in different projects to count in each project, choose this option. --autogen Count source code files that appear to be automatically generated. Normally these are excluded. --multiproject The different directories represent different projects; otherwise, it's assumed that all of the source code belongs to a single project. This doesn't change the total number of files or SLOC values, but it does affect the effort and schedule estimates. Given this option, effort is computed separately for each project (and then summed), and the schedule is the estimated schedule of the largest project. --filecount Display counts of files instead of SLOC. --wide Display in the "wide" (tab-separated) format. --details Display details, that is, results for every source code file. --effort F E Change the factor and exponent for the effort model. Effort (in person-months) is computed as F*(SLOC/1000)^E. --schedule F E Change the factor and exponent for the schedule model. Schedule (in months) is computed as F*(effort)^E. --personcost cost Change the average annual salary to cost. --overhead overhead Change the overhead value to overhead. Estimated cost is computed as effort * personcost * overhead. --addlang language Add a language not considered by default to be a ``language'' to be reported. Currently the only legal values for language are "makefile", "sql", and "html". These files are not normally included in the SLOC counts, although their SLOCs are internally calculated and they are shown in the file counts. If you want to include more than one such language, do it by passing --add- lang more than once, e.g., --addlang makefile --addlang sql. --addlangall Add all languages not normally included in final reports. NOTES
As with many other programs using Unix-like options, directories whose names begin with a dash (``-'') can be misinterpreted as options. If the directories to be analyzed might begin with a dash, use the double-dash (``- -'') to indicate the end of the option list before listing the directories. BUGS
Filenames with embedded newlines (in the directories or their descendants) won't be handled correctly; they will be interpreted as separate filenames where the newlines are inserted. An attacker could prevent sloccount from working by creating filenames of the form /nor- mal/directory ... NEWLINE/dev/zero. Such filenames are exceedingly rare in source code because they're a pain to work with using other tools, too. Future versions of sloccount may internally use NUL-separated filenames (like GNU find's -print0 command) to fix this. There are many more languages not yet handled by SLOCCount. SLOCCount only reports physical source lines of code. It would be very useful if it could also report logical lines of code, and perhaps other common metrics such as McCabe's complexity measures and complexity density (complexity/SLOC for each function or procedure). SEE ALSO
See the SLOCCount website at http://www.dwheeler.com/sloccount. Note that more detailed documentation is available both on the website and with the SLOCCount package. AUTHOR
David A. Wheeler (dwheeler@dwheeler.com). SLOCCount 31 July 2004 SLOCCOUNT(1)
All times are GMT -4. The time now is 03:06 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy