Skip to content

Instantly share code, notes, and snippets.

@andrewgiessel
Created August 28, 2013 16:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewgiessel/6368061 to your computer and use it in GitHub Desktop.
Save andrewgiessel/6368061 to your computer and use it in GitHub Desktop.
IPython notebook for replacing text in a file.
{
"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