Skip to content

Instantly share code, notes, and snippets.

View ashwaqar's full-sized avatar

Ashwaq ashwaqar

View GitHub Profile
@ashwaqar
ashwaqar / replace_lines_in_file.py
Created June 17, 2021 13:02 — forked from kirang89/replace_lines_in_file.py
Simple, clean way of replacing lines in a file
#! /usr/bin/env python
# -*- coding: utf-8 -*-
from tempfile import mkstemp
from shutil import move
from os import remove
import sys
def replace(source_file_path, pattern, substring):
fh, target_file_path = mkstemp()