Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have two variables

source_repo="fdl_ppe_01_04_repos_svc"
target_repo="fdl_ppe_01_10_repos_svc"

and I currently do a substitution within an XML file to replace all instances of $source_repo with $target_repo:

sed "s/$source_repo/$target_repo/g" $1 > $1_changed

How do I format the sed command so that it matches the pattern "fdl_ppe_01_XX_repos_svc" and replaces with $target_repo (XX can only be two digits)

...basically I don't want to have to define $source_repo in the script anymore

I'm struggling to understand sed syntax, so any help is appreciated!

share|improve this question
3  
Use source_repo="fdl_ppe_01_[0-9][0-9]_repos_svc", and always double quote your variable "$1". – cuonglm Mar 9 at 9:03
    
Many thanks for the super fast response! Worked perfectly. – Chris Finlayson Mar 9 at 11:26

Used character matching in your sed command:

Character Class - [:digit:] = Numeric digits [0-9]

sed "s/fdl_ppe_01_[0-9][0-9]_repos_svc/$target_repo/g" $1 > $1_changed

$1_changed will give you desired output I believe.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.