Skip to content

Instantly share code, notes, and snippets.

@tshrinivasan
Created November 22, 2019 07:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tshrinivasan/08c691b87b7a83ec0e28052916e91264 to your computer and use it in GitHub Desktop.
Save tshrinivasan/08c691b87b7a83ec0e28052916e91264 to your computer and use it in GitHub Desktop.
A program to find and replace bibliographical data
# program name : fix_records.py
# author : tshrinivasan@gmail.com
# version : 0.1
import sys
import os
import argparse
parser = argparse.ArgumentParser(description='A program to find and replace bibliographical data')
parser.add_argument("--input", default=None, type=str, help="Input File name")
if len(sys.argv) < 2:
parser.print_help()
sys.exit(1)
args = parser.parse_args()
input_file = args.input
output_file = "fixed_" + input_file
if os.path.exists(output_file):
os.remove(output_file)
infile = open(input_file).readlines()
outfile = open(output_file,"a")
print("\n=====START=====\n")
counter = 0
# Check 1
# check for lines that starts with =300
# if the line does not end with " p. "
# add " p. " at the end of the same line.
for line in infile:
if line.startswith("=300"):
if not line.endswith(" p."):
print("Replacing " + line)
line = line.strip() + " p. \n"
counter = counter + 1
outfile.write(line)
print("=====DONE=====\n")
print("Replaced " + str(counter) + " entries.")
print("Check the file : " + output_file)
print("Completed\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment