Skip to content

Instantly share code, notes, and snippets.

@Demannu
Created May 13, 2016 00:26
Show Gist options
  • Save Demannu/54cca86842635ed20c1911015f1ea24c to your computer and use it in GitHub Desktop.
Save Demannu/54cca86842635ed20c1911015f1ea24c to your computer and use it in GitHub Desktop.
Line2Line Python Script
#!/usr/bin/python
import sys, getopt
from itertools import izip
def main(argv):
source = ''
target = ''
try:
opts, args = getopt.getopt(argv,"hs:t:",["source=","target="])
except getopt.GetoptError:
print 'l2l.py -s <File to append from> -t <File to append to>'
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print 'l2l.py -s <File to append from> -t <File to append to>'
sys.exit()
elif opt in ("-s", "--source"):
source = arg
elif opt in ("-t", "--target"):
target = arg
source_file = open(source)
target_file = open(target)
with open('result.txt', 'w') as result, target_file as t, source_file as s:
for line1, line2 in zip(t, s):
result.write("{} {}\n".format(line1.rstrip(), line2.rstrip()))
if __name__ == "__main__":
main(sys.argv[1:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment