Home > Back-end >  sed regex pre-append not working with a different input
sed regex pre-append not working with a different input

Time:06-25

I have the following sed replace, which works correctly

$ echo "1.1.1.1\n2.2.2.2" | sed "s/^/allow /g; s/$/;/g"
allow 1.1.1.1;
allow 2.2.2.2;

However, when I run the same regex against a list of IPs, it shows incorrectly

$ wget -q https://api.bunny.net/system/edgeserverlist/plain -O - | sed "s/^/allow /g; s/$/;/g"
;llow 84.17.46.49
;llow 185.93.1.242
;llow 185.152.67.139
...

What I am doing wrong?

CodePudding user response:

You can remove all carriage returns at the end of lines before running your sed commands:

sed "s/\r$//g; s/^/allow /g; s/$/;/g"

This will output a list of allow IPs:

allow 89.187.185.87;
allow 212.102.50.49;
allow 84.17.46.50;
allow 89.187.173.70;
allow 89.187.185.163;
allow 84.17.37.209;
allow 89.187.185.162;
allow 89.187.188.223;

etc.

  • Related