Skip to content

Instantly share code, notes, and snippets.

@jreisinger
Last active January 23, 2018 11:56
Show Gist options
  • Select an option

  • Save jreisinger/1662e28e5dd4f0f244b110e5b6d9980e to your computer and use it in GitHub Desktop.

Select an option

Save jreisinger/1662e28e5dd4f0f244b110e5b6d9980e to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
""" Print line number and line from /etc/passwd with the given UID.
"""
##########
UID = 1000
##########
import fileinput, sys
with fileinput.input( files=('/etc/passwd') ) as fileinput:
for line in fileinput:
if int(line.split(':')[2]) == UID:
print("[{}] {}".format(fileinput.lineno(), line), end="")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment