Issue
I am trying to get a list of mirrors from https://mirrors.slackware.com/mirrorlist/ . I have a regex statement that gets the list of all of the servers (http://[a-zA-Z0-9-./]*), but I am trying to find a way to select only the ones from a specific country code (us, ca etc).
I am new to regex, so this might be something really easy I am overlooking. I have tried if|then statement, but with no luck. Any help would be appreciated. I have done a lot of searching, just in case this is a duplicate of another question.
I am not sure how the duplicate that they are saying is similar to mine is at all applicable. That is about if statements in bash, and not downloading and parsing information for which I was asking.
Solution
There are more efficient and elegant ways to do this, but consider this a small tutorial on the effectiveness of the *nix command line:
grep https: mirrors.lst | grep -E '^(us|se)' | sed -n 's/^.*=//;s:.*[>]/::;s:[<]/a[>]::;s:^.*[/][>]::p'
output
https://ftp.acc.umu.se/mirror/slackware.com/
https://ftpmirror.infania.net/slackware/
https://dfw.mirror.rackspace.com/slackware/
https://ftp.ussg.indiana.edu/linux/slackware/
https://mirror.cs.princeton.edu/pub/mirrors/slackware/
https://mirror.fcix.net/slackware/
https://mirror.slackbuilds.org/slackware/
https://mirror2.sandyriver.net/pub/slackware/
https://mirrors.kernel.org/slackware/
https://mirrors.ocf.berkeley.edu/slackware/
https://mirrors.syringanetworks.net/slackware/
https://mirrors.xmission.com/slackware/
https://plug-mirror.rcac.purdue.edu/slackware/
To get the additional schemes, you can use the Extended RegExp feature of grep
with the -E
flag, i.e.
grep -E 'ftp:|http:|https:|PUBLIC:|rsync:|xml:' mirrors.lst | grep -E '^(us|se)' | sed -n 's/^.*=//;s:.*[>]/::;s:[<]/a[>]::;s:^.*[/][>]::p'
Tnx to @Reilas for that hint!
You'll have to change the 2nd grep
target to be a list of any/all country codes you want to filter on. Separate each value with the |
char as shown here.
If something stops working, then execute each section of that pipeline from left to right (addivitely) until you see where the problem is.
Answered By - shellter Answer Checked By - Pedro (WPSolving Volunteer)