Skip to content

Instantly share code, notes, and snippets.

@gsathya
Forked from shadeslayer/tail.py
Created January 16, 2012 17:49
Show Gist options
  • Save gsathya/1622002 to your computer and use it in GitHub Desktop.
Save gsathya/1622002 to your computer and use it in GitHub Desktop.
import sys
import linecache
import os
if os.path.isfile(sys.argv[1]):
try:
with open(sys.argv[1], 'r') as f:
content = f.readlines()
length = len(content)
except IOError as e:
print 'File does not exist'
isFile = True
else:
f = sys.stdin
g = f.readlines()
length = len(g)
isFile = False
if isFile:
if int(sys.argv[2]) >= 0:
myArg = int(sys.argv[2])
else:
myArg = 5
mark = length - myArg + 1
for i in range(mark, length+1):
sys.stdout.write(linecache.getline(sys.argv[1], i))
else:
if int(sys.argv[1]) >= 0:
myArg = int(sys.argv[1])
else:
myArg = 5
mark = length - myArg
for i in range(mark, length + 1):
sys.stdout.write(g[i])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment