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. There are other lines in this file and the lines can not get out of order. I know I can do something like perl -p -i.bak -e 's/\/fs/fs\\/fs/g' filecheck but this command does not like the /fs/fs/fs's. Any thoughts and thank you!
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
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
participants (3)
-
John Lamb
-
Patrick B. O'Brien
-
Wybo Dekker