博文

目前显示的是标签为“sed”的博文

sed不支持非贪婪匹配 改用perl

问题 之前   Free.vps.vc 访问GitHub资源出错 用GithubProxy代理 用sed修改脚本内容 实践: bash <(curl -L  https://github.crazypeace.workers.dev/ https://github.com/crazypeace/v2ray_wss/raw/main/install.sh   | sed -E "$(curl -L  https://github.crazypeace.workers.dev/ https://github.com/crazypeace/gh-proxy/raw/master/sed-E-para )" ) 发现这个处理方法并不完美。 用grep github把涉及修改的地方输出一下。 curl -L  https://github.crazypeace.workers.dev/ https://github.com/crazypeace/v2ray_wss/raw/main/install.sh   | sed -E "$(curl -L  https://github.crazypeace.workers.dev/ https://github.com/crazypeace/gh-proxy/raw/master/sed-E-para )" | grep github 发现,.sh 的部分, bash <(curl -L https://github.crazypeace.workers.dev/ https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh | sed -E "$(curl -L https://github.com/crazypeace/gh-proxy/raw/master/sed-E-para)" ) --version 4.45.2 只在前面加了 github proxy,后面调用 GitHub 资源的部分并没有处理。 分析 查了一下资料发现,sed只有贪婪匹配,所以改用 perl 实操 perl用来做正则替换的参数为 -pe,里面同样支持sed语法的s命令 如 p

Free.vps.vc 访问GitHub资源出错 用GithubProxy代理 用sed修改脚本内容

图片
问题 Free.vps.vc 访问GitHub资源出错 --update sed不支持非贪婪匹配 改用perl 修改后 bash <(curl -L  https://github.crazypeace.workers.dev/ https://github.com/crazypeace/v2ray_wss/raw/main/install.sh   | perl -pe "$(curl -L  https://github.crazypeace.workers.dev/ https://github.com/crazypeace/gh-proxy/raw/master/perl-pe-para )" ) 解决思路 用 GitHub Proxy 代理 source:  https://github.com/hunshcn/gh-proxy 要么fork一份脚本,自己修改添加gh-proxy,如下文教程 如何设置自定义gh-proxy参数使用我的warp脚本 要么就把脚本下载到本地,然后修改脚本。有手搓和sed命令替换两条路。 手搓方法 1. 自己搭 或者 使用现成的 GitHub Proxy . 以  https://github.crazypeace.workers.dev/  为例 2. 在你的 GitHub 资源 url 的前面加上 GitHub Proxy 的 url  如: bash <(curl -L https://github.com/crazypeace/v2ray_wss/raw/main/install.sh) 修改为 bash <(curl -L  https://github.crazypeace.workers.dev/ https://github.com/crazypeace/v2ray_wss/raw/main/install.sh) 3. 如果你的资源是一个脚本,而这个脚本里面访问了GitHub资源 3.1 那么你可以先 wget 下来 wget  https://github.crazypeace.workers.dev/ https://github.com/crazypeace/v2ray_wss/raw/main/install.sh 这里下载下来的是文件名是 install.sh

sed 命令中的 / 可以用任意字符替换 特别地当处理网址相关问题时

官方说明: The  /  characters may be uniformly replaced by any other single character within any given  s  command. The  /  character (or whatever other character is used in its stead) can appear in the  regexp  or  replacement  only if it is preceded by a  \  character. 来源: https://www.gnu.org/software/sed/manual/sed.html#The-_0022s_0022-Command 如: sed -E 's#(http.*github[^/]*/)#https://github.crazypeace.workers.dev/\1#g' 和 sed -E 's/(http.*github[^/]*\/)/https:\/\/github.crazypeace.workers.dev\/\1/g' 等同。

sed -e 和 sed -E 的区别 如果讨厌在(前面加\,那么就使用 -E参数吧

图片
官方说明:   -E, -r, --regexp-extended                  use extended regular expressions in the script                  (for portability use POSIX -E). 详细解释 5.2 Basic (BRE) and extended (ERE) regular expression Basic and extended regular expressions are two variations on the syntax of the specified pattern. Basic Regular Expression (BRE) syntax is the default in  sed  (and similarly in  grep ). Use the POSIX-specified  -E  option ( -r ,  --regexp-extended ) to enable Extended Regular Expression (ERE) syntax. In GNU  sed , the only difference between basic and extended regular expressions is in the behavior of a few special characters: ‘ ? ’, ‘ + ’, parentheses, braces (‘ {} ’), and ‘ | ’. With basic (BRE) syntax, these characters do not have special meaning unless prefixed with a backslash (‘ \ ’); While with extended (ERE) syntax it is reversed: these characters are special unless they are prefixed with backslash (‘ \ ’). source:  https://www.gnu.org/software/sed/manual/sed.html#BRE-vs-ERE

脚本修改Caddyfile,显示Aria2的rpc密钥

之前搭了一个GCP的VM环境,做好了快照。有需要的时候,新建一个VM实例下载,用完了就删除VM实例。 这样每次建好快照以后,都要去修改Caddyfile里的IP地址。 写了个小脚本来修改Caddyfile的IP地址,再显示一下Aria2的rpc密码,方便填写到AriaNG页面上去。 #!/usr/bin/env bash caddyfile="/etc/caddy/Caddyfile" aria2_conf="/root/.aria2/aria2.conf" read -p "输入VPS的IP地址:" vps_ip if [[ ! -e ${caddyfile} ]]; then echo -e "Caddy 配置文件不存在 !" && exit 1 fi sed -i '1 c '${vps_ip}':80 {' ${caddyfile} service caddy restart if [[ ! -e ${aria2_conf} ]]; then echo -e "Aria2 配置文件不存在 !" && exit 1 else conf_text=$(cat ${aria2_conf}|grep -v '#') aria2_passwd=$(echo -e "${conf_text}"|grep "rpc-secret="|awk -F "=" '{print $NF}') fi echo "Aria2的rpc密码: ${aria2_passwd}" 其中 sed -i ' 1 c xxxxxx ' ${caddyfile} 的意思就是把第 1 行 改写 为 xxxxxx Caddyfile可以写成这样 localhost:80 {        #第一行写什么不重要,反正会被init.sh脚本修改掉     gzip     root /usr/local/caddy/www/fi

The Hot3 in Last 30 Days

无服务器 自建短链服务 Url-Shorten-Worker 完整的部署教程

ClouDNS .asia免费域名 托管到CloudFlare开CDN白嫖Websocket WS通道翻墙 / desec.io