Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Regular expression

Options
  • 20-04-2016 7:14pm
    #1
    Registered Users Posts: 208 ✭✭


    Looking for a regex that would search sql scripts for

    Any instance of the words create alter or drop
    But exclude comments /** or --

    Some success with (Alter)*(create)
    Can't find an example (in a hurry to produce a list of objects promoted to test) that could do this.

    Any help or expressions appreciated.

    Whitey


Comments

  • Registered Users Posts: 1,275 ✭✭✭bpmurray


    You want a regex to include in a program, or do you want a script to generate something? Do you want to change these verbs or do you want to simply highlight them? For example using grep you could do this:
    grep -i "create\|alter\|drop" filename.sql
    

    Of course, the choice of tools is limited to whatever is available on your chosen platform, so Windows is very poor, while Mac and Linux/UNIX are fine.


  • Closed Accounts Posts: 2,828 ✭✭✭5rtytry56


    OP, what flavour of SQL are you using?
    MySQL, SQL Server


  • Registered Users Posts: 208 ✭✭whiteboard


    the files to be searched are in a folder structure
    was looking to us the 'find in file' feature in VS which I find far more reliable than windows search.

    requirements
    search all files in a folder/sub-folder structure
    for all files containing instances create alter or drop

    of course - open to other methods of doing this


  • Registered Users Posts: 1,275 ✭✭✭bpmurray


    Try the following, using either Linux, or cygwin or similar on Windows
    grep -ril "create\|alter\|drop" *
    
    It will return a list of files containing one of the strings, case insensitive, recursing into subdirectories


  • Registered Users Posts: 1,109 ✭✭✭Skrynesaver


    In Linux/Cygwin, with checks for comments
    for $file in $(find /folder/subfolder -type f)
    do
      perl -ne '$in_comment++ if/\/\*/;$incomment-- if /\*\//;if (! $incomment){ if (print /(create|alter|drop)/ && !/--.+(create|alter|drop));}' 
    done
    


  • Advertisement
Advertisement