continued from this thread!
http://www.daniweb.com/software-development/python/threads/353210
i have a file which i am currently working on which will remove all pipes and replace them with a comma. that all works fine it the second bit i am currently stuck on..
i need to remove the first two CAPITAL letters from the numbers ie.
WHAT I NEED \/
EXTERNAL_PERSON_KECVY|USER_ID|FIRSTNAME|LASTNAME|EMAIL|EMAIL_IND
s100007|s100007|KiCVBm|ShotGDFGDter|K.ShoBBCVBtter@UCS.AC.UK|Y|Enabled|Y|
s100038|s100038|Lois|MansVBCVBfield|L.MansFGDFGfield@UCS.AC.UK|Y|Enabled|
WHAT I GET! \/
external_pERSON_KECVY|USER_ID|FIRSTNAME|LASTNAME|EMAIL|EMAIL_IND
s100007|s100007|KiCVBm|ShotGDFGDter|K.ShoBBCVBtter@UCS.AC.UK|Y|Enabled|Y|
s100038|s100038|Lois|MansVBCVBfield|L.MansFGDFGfield@UCS.AC.UK|Y|Enabled|
AS U CAN SEE THE FIRST LINE IS ALSO IN CAPS BUT I NEED TO KEEP IT THAT WAY.
HOW CAN I SORT THOUGH THE FILE AND REMOVE THE CAPS APART FROM THE FIRST LINE!
THIS IS WHAT I HAVE SO FAR
# created in python 3.2 by Dan Holding on the "14/03/2011"
import sys, string, pprint, re, os
if len(sys.argv) != 2:
print('Usage: CapR_PipeR inputFilename')
print('Where inputFilename is the name of the file to be processed,')
print('It will then remove capital letters from the staff or student number')
print('and replace pipes(|) with commas(,)on each line ')
exit(3)
Eline=list()
inFile = open(sys.argv[1],'r')
recordList = inFile.read()
inFile.close()
oldChar = '|'
newChar = ','
newRecordList = []
pprint.pprint( recordList)
pprint .pprint(sys.argv)
if re.match('.+', oldChar):
for record in recordList:
newRecordList.append(str.replace(record,oldChar,newChar))
outFile = open(sys.argv[1],'w')
outFile.writelines(newRecordList)
outFile.close()
inFile = open(sys.argv[1],'r')
recordList = inFile.read()
inFile.close()
lineN = 0
for line in recordList.splitlines():
lineN +=1
if lineN ==0:print(lineN)
else:
lineN +=1
Eline = (line[:10].lower()+line[10:]+ '\n')
outFile1 = open('temp.txt','a')
outFile1.writelines(Eline)
outFile1.close()
inFile1 = open('temp.txt','r')
recordList1 = inFile1.read()
inFile1.close()
outFile = open(sys.argv[1],'w')
outFile.writelines(recordList1)
os.remove('temp.txt')