Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Searching across all do files in a folder

    Hi. I would like to search through all my do files for the word "lasso". Is there any command that can do this? Thanks!

  • #2
    Assuming all your do-files are in a single folder (or subfolders of that folder):

    Code:
    //  FIRST MAKE SURE YOUR CURRENT WORKING DIRECTORY IS THE ONE CONTAINING THE FILES TO BE SEARCHED
    
    //  CREATE A DATA SET OF THE PATHNAMES
    filelist, pattern(*.do)
    
    //  READ IN THE FILES
    gen strL contents = fileread(dirname+"/"+filename)
    
    //  IDENTIFY THE ONES CONTAINING THE TARGET STRING
    gen long foundit = strpos(contents, "lasso")
    
    //  SHOW THE RESULTS
    list if foundit
    -filelist- is written by Robert Picard and is available from SSC.

    Added: If you don't want to include files in the subdirectories, add the -norecursive- option to the -filelist- command.

    Comment


    • #3
      I would use -grep- for this. It’s a command line utility from Linux but available with Mac and Windows (for windows, you’ll need something like Cygwin) I believe.

      Comment

      Working...
      X