Created
August 28, 2013 16:30
-
-
Save andrewgiessel/6368061 to your computer and use it in GitHub Desktop.
IPython notebook for replacing text in a file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "metadata": { | |
| "name": "replace text in files" | |
| }, | |
| "nbformat": 3, | |
| "nbformat_minor": 0, | |
| "worksheets": [ | |
| { | |
| "cells": [ | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "header_files = ['blah.txt']\n", | |
| "\n", | |
| "odor_name_to_replace = ''\n", | |
| "odor_name_to_use = ''\n", | |
| "\n", | |
| "\n", | |
| "for f in header_files:\n", | |
| " with open(f+'new', \"wt\") as out:\n", | |
| " for line in open(f):\n", | |
| " out.write(line.replace(odor_name_to_replace, odor_name_to_use))\n", | |
| " os.rename(f+'new', f)" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [], | |
| "prompt_number": 36 | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [] | |
| } | |
| ], | |
| "metadata": {} | |
| } | |
| ] | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment