#!/usr/bin/env python3 import os p = "/root/.git-credentials" with open(p, encoding="utf-8") as fh: for line in fh: line = line.rstrip("\n") if line.startswith("https://mercury:"): print("LINE_LEN", len(line)) print("USER_PART", line.split("//")[1].split(":")[0]) # password between 'mercury:' and '@' rest = line.split("//", 1)[1] # mercury:@forge... user, _, tail = rest.partition(":") host, _, port = tail.partition("/") print("PASSWORD_LEN", len(user)) print("HOST", host) print("FULL_URL", line) print("FORGE_TOKEN_EXTRACTED", user)