Enhancement of unix script [closed]

Bash is not very performant doing loops.
Since you tagged the question python, python should be ok?

def data_mask(col_val):
    mod = len(col_val) + sum(map(ord, col_val)) % 10
    result = ""
    for i, ch in enumerate(col_val, mod + 1):
        absnum = abs(ord(ch) - i)
        if 'A' <= ch <= 'Z':
            ch = chr(ord('A') + absnum % 26)
        elif 'a' <= ch <= 'z':
            ch = chr(ord('a') + absnum % 26)
        elif '0' <= ch <= '9':
            ch = chr(ord('0') + absnum % 10)
        else:
            ch = chr(ord('A') + absnum % 10)
        result += ch
    return result

while open(temp_outputfile) as lines:
    while open(outputfile, 'w') as output:
        output.write(next(lines))
        for line in lines:
            pre, col_val, post = line.split('|', 2)
            output.write("{}|{}|{}".format(pre, data_mask(col_val), post))

Leave a Comment