Skip to content

CLI Goodies

This page is a collection of handy OSX / Linux shell commands that have helped save time and effort while working, I thought as well as providing a place to document them as a reference, they might be handy for others to use.

  • This one-liner (using an inline for-loop) prints out the filenames of .xml file’s that contain a particular string pattern: “Level[0-9]*.pod”
    for f in $(find . -iname “*.xml”); do if [ 0 -lt `grep -ic "Level[0-9]*.pod” $f` ]; then echo $f; fi; done;
  • Another one-liner to convert line endings in .cpp files from windows to unix (this command is OSX specific, but will work on unicies with alteration of the sed call)
    for FILE in $(find . -iname “*.cpp”); do sed -i ” ‘s/.$//’ $FILE; done;
  • Python template for quick-and-dirty XML processing (mind the tabs, but you already knew that)
    import xml.dom.minidom;
    files = ['Data/Level/Athens/Model/Cinematic/athensIntro.xml'];
    def process_node(node, src):
      print propnode.attributes;
    for file in files:
      dom = xml.dom.minidom.parse(file);
      for node in dom.getElementsByTagName(‘MyParentElementName’):
        process_node(node, file);
Leave a Comment