Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

in current directory, there are some RunId from an experiment, is there any command to count number of RunId's separately at once. I am using now the following for each one of the RunId for the current directory: ls | grep RunId | wc -l

share|improve this question
    
What do you want to do exactly? Do you want to count the lines in a number of files as your question suggests? Or do you want to count the number of files containing "RunId" as per your example? –  Adaephon Feb 21 at 0:08
    
thanks a lot for your reply, in current directory, i have various runid from an experiment, i want to count the number of each runid in current directory. but by the above command i can count only one runid in the directory. for counting another runid i should manually type another script. –  user250549 Feb 21 at 0:22
    
So, just to confirm: You have multiple directories, in which may or may not be a file named "RunId". And you want to count how many directory actually do have this file? –  Adaephon Feb 21 at 6:00
    
Dear Adaephon, your sentence is correct thanks a lot. –  user250549 Feb 21 at 12:02

1 Answer 1

The command you ran would tell you the # of files containing RunId in the name in the current directory, say I wanted to do that in subdirectories as well I could do:

find . -type f -iname "*RunId*" | wc -l

or

find . -type f -exec basename | grep -c "RunId"

Edit based on further explanation of question: If there are multiple files containing RunId## in their name you could get the counts of each by

find . -iname "*RunId*" | grep -o -E "RunId[0-9]*" | sort | uniq -c | sort --stable -n -r
share|improve this answer
    
thanks a lot for your reply, in current directory, i have various runid from an experiment, i want to count the number of each runid. but by command ls | grep runId | wc -l i can count only one runid in the directory at a time. for counting another runid i should manually type another script. but i want count of runid's separated by commas –  user250549 Feb 21 at 5:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.