sed插入批量內容
批量修改文件內容一般使用sed,但是在插入多行內容和不同格式的時候就遇到困難了,今天終於知道怎麽處理了,記錄一下!
在一個文件裏包含image: 192.168.30.60的行下插入以下內容。
resources:
requests:
memory: "768Mi"
limits:
memory: "768Mi"
變更前:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: bi-web
spec:
replicas: 1
template:
metadata:
labels:
app: bi-web
spec:
containers:
- name: bi-web
image: 192.168.30.60:1179/test100/bi-web
ports:
- containerPort: 8080
命令:sed -i ‘/image: 192.168.30.60/a\ resources:\n requests:\n memory: "768Mi"\n limits:\n memory: "768Mi"‘ deploy.yml
變更後:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: bi-web
spec:
replicas: 1
template:
metadata:
labels:
app: bi-web
spec:
containers:
- name: bi-web
image: 192.168.30.60:1179/test100/bi-web
resources:
requests:
memory: "768Mi"
limits:
memory: "768Mi"
sed插入批量內容