wizurd
wizurd

Reputation: 3739

How to use cleartool find to get files containing a specific string?

I'm trying to search all files in a given branch for a specific string. So far I have

cleartool find . -branch 'brtype(<branch-name>)' -print

This gets all the files in the current directory for branch name "branch-name".
But I want to be able to search/grep those files.
How would yo do this?

Upvotes: 2

Views: 3819

Answers (1)

VonC
VonC

Reputation: 1324347

You can use an -exec directive of the command cleartool find in order to chain a grep command:

# Windows syntax 
cleartool find . -type f -branch 'brtype(MyBranch)' -exec "grep aSpecificString \"%CLEARCASE_PN%\""

# Unix syntax
cleartool find . -type f -branch 'brtype(MyBranch)' -exec 'grep aSpecificString "$CLEARCASE_PN"'

Note the -type f, to limit the search to files (not directories).

Note also that you will get the same file multiple times, if there are several versions of that file in the branch MyBranch.

To limit to one file result per branch, replace -branch by -ele (for 'element')
(as I illustrated in "How to find the files modified under a clearcase branch"):

# Unix syntax
cleartool find . -type f -ele 'brtype(MyBranch)' -exec 'grep aSpecificString "$CLEARCASE_PN"'

Upvotes: 2

Related Questions