Most viewed recipes tagged "meta:requires=fileinput" and "files" but not "utilities"http://code.activestate.com/recipes/tags/meta:requires=fileinput+files-utilities/views/2005-09-28T15:34:55-07:00ActiveState Code RecipesSort a file (Python)
2005-09-28T15:34:55-07:00Phil Robarehttp://code.activestate.com/recipes/users/2608288/http://code.activestate.com/recipes/440612-sort-a-file/
<p style="color: grey">
Python
recipe 440612
by <a href="/recipes/users/2608288/">Phil Robare</a>
(<a href="/recipes/tags/files/">files</a>).
</p>
<p>A simple (4 lines) recipe that will sort a file named on the command line and write the sorted lines to standard output.</p>
sed/awk : Python script to rename subdirectories of a directory tree, replace strings in files (Python)
2005-07-05T12:33:51-07:00Bibha Tripathihttp://code.activestate.com/recipes/users/2437311/http://code.activestate.com/recipes/435904-sedawk-python-script-to-rename-subdirectories-of-a/
<p style="color: grey">
Python
recipe 435904
by <a href="/recipes/users/2437311/">Bibha Tripathi</a>
(<a href="/recipes/tags/files/">files</a>).
</p>
<p>I needed to write a sed/awk Python equivalent for walking into a directory tree and renaming certain subdirectories, while also looking into all xml files on the way and replacing/modifying certain strings in those files.</p>
<p>It would be nicer if someone could suggest an enhanced re.sub(regex, replacement, subject) where I could replace all strings of a certain pattern with other strings of a certain pattern i.e. the second argument in re.sub namely 'replacement' would then be a regular expression and would be a different string for each different string in 'subject' that matches with the pattern 'regex'. For example 'arthinternational-d' would be replaced by 'arthinternational-r', 'arthfmt-d' would be replaced by 'arthfmt-r' but 'a-d' would remain unmodified.</p>