Club 15CC

Command Line ~ 15CC Code

Task Code
Python Boilerplate Code for a Python Command Line Utility »
#!/usr/bin/python
import os.path
import sys
from optparse import OptionParser  # <= 2.6. Use argparse for >= 2.7

def main(args=None):
    # Allows calling main directly with args passed as a list.
    if args is None:
        args = sys.argv

    parser = OptionParser()
    parser.add_option("-f", "--file", dest="filename",
                      help="write report to FILE", metavar="FILE")
    parser.add_option("-q", "--quiet",
                      action="store_false", dest="verbose", default=True,
                      help="don't print status messages to stdout")

    (options, args) = parser.parse_args(args)

    # return > 0 for errors

if __name__ == "__main__":
    sys.exit(main())
Linux Search and replace on files from the BASH command line… » -i is for writing the result back to the file. -e...
# All files...
sed -ie "s/IM/MC/g" *

# More flexibility
find ./ -name "*.m" | xargs sed -ie "s/IM/MC/g" *