tags:

views:

46

answers:

3

hi

i have a config file xml

<tflow name="CENTRE"
     inputDTD="/JOBS/cnav/etc/jobReporting/batch/dtd/dtd-ContactCentre.dtd"
     inputFile="/JOBS/cnav/etc/jobReporting/import/2010.05.02.CONTACTCENTRE.xml"
                 logPath="/JOBS/cnav/etc/jobReporting/logs/"
                 rejectPath="/JOBS/cnav/etc/jobReporting/rejets/"/>
            <tflow name="SKILL"
                 inputDTD="/JOBS/cnav/etc/jobReporting/batch/dtd/dtd-Skill.dtd"
                 inputFile="/JOBS/cnav/etc/jobReporting/import/2010.05.02.SKILLS.xml"
                 logPath="/JOBS/cnav/etc/jobReporting/logs/"
                 rejectPath="/JOBS/cnav/etc/jobReporting/rejets/"/>

my shell is aim to change, by example '2010.05.02.SKILLS.xml' with 'newdate.SKILLS.xml'

currently i think of SED, i wrote:

sed 's/(import\/)(\d{4}.\d{2}.\d{2})/$1$newdate/g' myfile.xml

it doesn't work,i test the pattern with RegExr(a site) which is fine.

is it a problem of synthesis of SED? thanks.

A: 

Depending on your sed implementation, you may have to specify that you are using regex. What OS/version of sed are you using? You may, for example, have to use the -E argument.

Joshua Smith
Which version of `sed` has `-E`? By the way, `sed` *always* uses regexes. Perhaps you're thinking of *extended* regexes. Some `sed` versions use `-r` to enable that. `grep` does have `-E` - maybe that's what you're thinking of.
Dennis Williamson
+1  A: 

So many regex dialects around... I think sed does not understand \d. Besides, use \1 for the bactracking, and use double quotes if $newdate is a shell variable. And try -r to use extended regex.

Try something like this

   sed -r "s/(import\/)([0-9]{4}\.[0-9]{2}\.[0-9]{2})/\1$newdate/g" myfile.xml
leonbloy
thanks,it works
chun
+1  A: 

Most sed implementations don't support extended regexps by default, so you need to use basic regexps. This means you need to put backslashes before your parentheses and braces, and you can't use the \d class. You also have the syntax of backreferences wrong -- it should be \1, not $1$. So, it should look like this:

 sed 's/\(import\/\)\([0-9]\{4\}\.[0-9]\{2\}\.[0-9]\{2\}\)/\1newdate/' myfile.xml
Adam Rosenfield