20 Jan
2005
20 Jan
'05
08:57
Patrick B. O'Brien wrote:
I need perl, or something equivalent to it to read through a file checking for a line containing /fs/fs/fs and to change this to /fs.
This line may have either a /fs, /fs/fs or a /fs/fs/fs/fs; it will always start in the first position, so ^ is good to use.
Any thoughts and thank you!
Try: /////////////////////////////////////////////////// #! /usr/bin/python import re file = open( 'file' ) # change this bit line = file.readline() while line: line = re.sub( r'^(/fs)+', '/fs', line ) print line, line = file.readline() file.close() //////////////////////////////////////////////////// This is python rather than Perl, but ought to work. -- JDL