On Thu, 20 Jan 2005, John Lamb wrote:
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.
try: $ perl -pe 's|^(/fs)+|/fs|' test or, to do it in place: $ perl -i -pe 's|^(/fs)+|/fs|' test or, keeping a backup copy: $ perl -i.bak -pe 's|^(/fs)+|/fs|' test
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.
-- Wybo