@@ -0,0 +1,1853 @@
+#! /usr/bin/python%0A# -*- coding: utf-8 -*-%0A%0A%22%22%22%0ACopyright 2015 Sebastien Quioc%0A%0A   Licensed under the Apache License, Version 2.0 (the %22License%22);%0A   you may not use this file except in compliance with the License.%0A   You may obtain a copy of the License at%0A%0A       http://www.apache.org/licenses/LICENSE-2.0%0A%0A   Unless required by applicable law or agreed to in writing, software%0A   distributed under the License is distributed on an %22AS IS%22 BASIS,%0A   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A   See the License for the specific language governing permissions and%0A   limitations under the License.%0A%22%22%22%0A%0Afrom __future__ import print_function%0Aimport sys%0Aimport argparse%0Aimport functools%0A%0Adef substring(entry, start, length):%0A    %22%22%22%0A    %3E%3E%3E substring(None, 12, 6)%0A    ''%0A    %3E%3E%3E substring(%22tooshort%22, 12, 6)%0A    ''%0A    %3E%3E%3E substring(%22thisverylongstringshouldbetruncated%22, 12, 6)%0A    'string'%0A    %3E%3E%3E substring(%22thisstringshouldnotbetruncated%22, 0, 30)%0A    'thisstringshouldnotbetruncated'%0A    %22%22%22%0A    if entry is None or len(entry) %3C start:%0A        return %22%22%0A    elif len(entry) %3C start + length:%0A        return entry%5Bstart:%5D%0A    else:%0A        return entry%5Bstart:start+length%5D%0A%0Aif __name__ == %22__main__%22:%0A    parser = argparse.ArgumentParser(description='substring input lines')%0A    parser.add_argument('--test', dest='test', action='store_true', help=%22execute unit doctests%22)%0A    parser.add_argument('start', nargs='?', default=0, type=int, help='the start of the substring')%0A    parser.add_argument('length', nargs='?', type=int, help='the length of the substring')%0A    args = parser.parse_args()%0A%0A    if args.test:%0A        import doctest%0A        doctest.testmod()%0A    else:%0A        currified = functools.partial(substring, start=args.start, length=args.length)%0A        map(print, map(currified, sys.stdin.readlines()))%0A%0A

Add first manipulation tools