#!/bin/sh """": # -*-python-*- exec env LC_CTYPE=iso-8859-1 python "$0" ${1+"$@"} """ from __future__ import absolute_import, print_function import sys py_maj = sys.version_info[0] import argparse if py_maj > 2: byte_stream = lambda x: x.buffer from os import fsencode else: byte_stream = lambda x: x fsencode = lambda x: x parser = argparse.ArgumentParser() parser.add_argument('-l', nargs=2, metavar=('ORIG', 'NEW'), action='append', help='literally replace ORIG with NEW') opt = parser.parse_args() sys.stdout.flush() with byte_stream(sys.stdin) as stdin: content = stdin.read() for orig, new in opt.l: content = content.replace(fsencode(orig), fsencode(new)) byte_stream(sys.stdout).write(content)