#!/usr/bin/env python3 import pwd, sys, os, re, shutil, time, subprocess, datetime, operator, signal, math t_inp = "/tmp/x.5" t_out = "/tmp/x.6" with open(t_inp,encoding="latin") as f: buf = f.read().splitlines() f.close() out = [] for i in range(0,len(buf)): line = buf[i].strip("\n") if ( line[20:21] == "|" ): line = line.replace("RadioS"," ").replace("VisS "," ").replace("* "," ") o_type = line[83:89] if ( len(line) > 92 ): g_type = line[91:] else: g_type = "" if ( i == len(buf) or o_type == "BLLac " or o_type == "QSO " or o_type == "QSOc " ): out.append ( line ) continue for j in range(i+1,len(buf)): lin = buf[j].replace("RadioS"," ").replace("VisS "," ").replace("* "," ").strip("\n") if ( lin[20:21] == "|" ): break if ( o_type == " " ): if ( lin[83:89] == "G " or \ lin[83:89] == "BLLac " or \ lin[83:89] == "QSO " or \ lin[83:89] == "QSOc " ): o_type = lin[83:89] if ( len(lin) > 92 ): g_type = lin[91:] if ( g_type == "" ): out.append ( line[0:83] + o_type + "|" ) else: out.append ( line[0:83] + o_type + "| " + g_type ) f = open ( t_out, "w" ) for line in out: print ( line, file=f ) f.close()