Home > Mobile >  How to replace a string whether there are prefix or no?
How to replace a string whether there are prefix or no?

Time:01-23

I'm trying to automate my server installation, one of the things I want to do is changing the mirror from main mirror/regional to my mirror of choice.

Is there any sed or awk command that will replace/catch ??.archive.ubuntu.com or archive.ubuntu.com to mirror.sg.gs ? Preferably in one command since I believe it is possible (with regex ?) but I haven't look into it.

Basically, I want replace.

us.archive.ubuntu.com
archive.ubuntu.com
de.archive.ubuntu.com
sg.archive.ubuntu.com
jp.archive.ubuntu.com

To following.

mirror.sg.gs
mirror.sg.gs
mirror.sg.gs
mirror.sg.gs
mirror.sg.gs

CodePudding user response:

Here's a solution for perl:

perl -pe 's/(\S \.)?archive\.ubuntu\.com/mirror.sg.gs/g'
  • Related