#!/usr/bin/python import re data_file = '/home/chansen4/.cache/notify-osd.log' entries = [] tmp_entry = '' fp = open(data_file, 'r') for line in fp: if len(line.strip()) == 0: entries.append(tmp_entry) tmp_entry = '' else: tmp_entry += line fp.close() lastEntries = [] for entry in entries[-4:]: garbage = re.sub('^\[([^\]]+)\]\s+', '', entry) lastEntries.append(garbage) parts = garbage.split("\n") print "${color #000}${offset 20}%s ${color #222}--- ${color #000}%s ${color #222}${hr 1}\n" % (parts[0], parts[1])