1

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!

2
  • 3
    Use source_repo="fdl_ppe_01_[0-9][0-9]_repos_svc", and always double quote your variable "$1".
    – cuonglm
    Commented Mar 9, 2016 at 9:03
  • Many thanks for the super fast response! Worked perfectly. Commented Mar 9, 2016 at 11:26

1 Answer 1

0

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .