首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用sed替换shell脚本中的cron?

如何使用sed替换shell脚本中的cron?
EN

Stack Overflow用户
提问于 2022-06-07 11:01:38
回答 1查看 103关注 0票数 0

我需要使用sed或awk替换文件中的cron条目。

试过这个:没起作用

代码语言:javascript
复制
sed -i 's/0 0 * * 0/0 1 * * 1/g' script.sh

script.sh

代码语言:javascript
复制
#!/bin/bash

mkdir -p .github/workflows

cd .github/workflows
touch semgrep.yml

cat << EOF > semgrep.yml
name: Semgrep
on:
  pull_request: {}
  push:
    branches:
      - master
      - main
    paths:
      - .github/workflows/semgrep.yml
  schedule:
    - cron: '0 0 * * 0'
jobs:
  semgrep:
    name: Static Analysis Scan
    runs-on: ubuntu-18-04

请帮我同样的忙。

EN

回答 1

Stack Overflow用户

发布于 2022-06-07 15:48:25

使用mikefarah/yq编辑文件就位(-i):

代码语言:javascript
复制
yq -i '.on.schedule[].cron = "0 1 * * 1"' semgrep.yml

将打开包含以下内容的semgrep.yml

代码语言:javascript
复制
name: Semgrep
on:
  pull_request: {}
  push:
    branches:
      - master
      - main
    paths:
      - .github/workflows/semgrep.yml
  schedule:
    - cron: '0 0 * * 0'
jobs:
  semgrep:
    name: Static Analysis Scan
    runs-on: ubuntu-18-04

变成一个包含

代码语言:javascript
复制
name: Semgrep
on:
  pull_request: {}
  push:
    branches:
      - master
      - main
    paths:
      - .github/workflows/semgrep.yml
  schedule:
    - cron: '0 1 * * 1'
jobs:
  semgrep:
    name: Static Analysis Scan
    runs-on: ubuntu-18-04
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72530054

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档