sed替换写法sed -e 's; ;:;g'

本文介绍了一种使用SED命令进行字符串替换的技巧,展示了如何利用分号作为分隔符代替传统的斜杠,通过实例对比两种写法的效果,加深了对SED命令灵活使用的理解。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

sed替换的两种写法,今天看脚本的时候遇到了一个没见过的写法:

用;替代/的

如下:

 

root@iZ2zegl8h62gwjeuf4d47lZ:~# echo "hello;nihao" | sed -e 's;\;;:;g'     #####   ;代替了 /  等同于下面的写法

hello:nihao

root@iZ2zegl8h62gwjeuf4d47lZ:~# echo "hello;nihao" | sed -e 's/\;/:/g'

hello:nihao

转载于:https://www.cnblogs.com/if-then/p/7202624.html

deployment.yaml # deployment.yaml apiVersion: apps/v1 kind: Deployment metadata: name: iot-frontend namespace: iot-system spec: replicas: 2 selector: matchLabels: app: iot-frontend template: metadata: labels: app: iot-frontend spec: imagePullSecrets: - name: regcred # 引用私有仓库凭证 containers: - name: frontend image: crpi-itsb0fkqsy8d4os4.cn-hangzhou.personal.cr.aliyuncs.com/zjjxyqy/iot-frontend:V1.0 ports: - containerPort: 80 env: - name: BACKEND_SERVICE # 注入后端服务地址 value: "iot-backend.iot-system.svc.cluster.local" volumeMounts: - name: config-volume mountPath: /etc/nginx/conf.d/nginx.conf subPath: nginx.conf - name: config-volume mountPath: /usr/share/nginx/html/config.js subPath: config.js # 启动时替换占位符 command: ["/bin/sh", "-c"] args: - | # 动态替换配置文件中的变量 envsubst '$${BACKEND_SERVICE}' < /etc/nginx/conf.d/nginx.conf > /etc/nginx/conf.d/nginx.conf.tmp && mv /etc/nginx/conf.d/nginx.conf.tmp /etc/nginx/conf.d/default.conf envsubst '$${BACKEND_SERVICE}' < /usr/share/nginx/html/config.js > /usr/share/nginx/html/config.js.tmp && mv /usr/share/nginx/html/config.js.tmp /usr/share/nginx/html/config.js exec nginx -g 'daemon off;' volumes: - name: config-volume configMap: name: app-config # 挂载ConfigMap --- # 创建后端服务(必需) apiVersion: v1 kind: Service metadata: name: iot-backend namespace: iot-system spec: selector: app: iot-backend # 匹配后端应用标签 ports: - protocol: TCP port: 8080 targetPort: 8080 [root@k8s-master frontend]# kubectl logs iot-frontend-797b8bf6c5-cqprf -n iot- system mv: can't rename '/usr/share/nginx/html/config.js.tmp': Resource busy 2025/07/13 08:09:02 [emerg] 1#1: unknown "backend_service" variable nginx: [emerg] unknown "backend_service" variable [root@k8s-master frontend]#
最新发布
07-14
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值