Linux shell bash - cat文件做一个sed来替换和保存[关闭]

1sbrub3j  于 2023-03-30  发布在  Shell
关注(0)|答案(1)|浏览(113)

已关闭。此问题需要details or clarity。当前不接受答案。
**想要改进此问题?**添加详细信息并通过editing this post阐明问题。

7小时前关闭。
Improve this question
我需要在下面的文本中插入一个新行。
cat命令使grep查找应该插入我想要的内容的行。

- "Experimentation":
    - "Overview": experimentation/index.md
    - "home AB":
          - "Overview": experimentation/home-ab/index.md
          - "Metrics": experimentation/home-ab/metricas/index.md
          - "Adtional Metrics":
                - "User Frequency": experimentation/home-ab/metricas/frequencia.md
                - "MVT": experimentation/home-ab/metricas/mvt.md
                - "INSERT": NEW_LINE_INCREMENT
    - "home MAB":
          - "Overview": experimentation/home-mab/index.md
          - "Criação Standard MAB": experimentation/home-mab/criacao-experimento.md

这个文本是mkdocs.yml的一部分,对于每个管道,我需要增加一个链接。
我使用的命令是:

cat mkdocs.yml | grep -B 1 '"home MAB"' | sed 's/.md/\n                            - "b_metric": experimentation\/globo-ab\/metricas\/b_metric/'

我需要在块- "Adtional Metrics":中增量插入新行并保存文件。
我希望每次运行脚本时都增加换行符,添加B和c_metric

- "Adtional Metrics":
                - "User Frequency": experimentation/home-ab/metricas/frequencia.md
                - "Page View": experimentation/home-ab/metricas/pageviews.md
                - "Session Count": experimentation/home-ab/metricas/session_count.md
                - "Click Followed by Play": experimentation/home-ab/metricas/click_followed_by_play.md
                - "Video Watch": experimentation/home-ab/metricas/videos.md
                - "MVT": experimentation/home-ab/metricas/mvt.md
                - "INSERT": NEW_LINE_INCREMENT
                - "b_metric": text_text_text.md
                - "c_metric": text_text_text.md
hl0ma9xz

hl0ma9xz1#

例如,这是mkdocs.yml(我稍微修改了一下,使其更具可读性)。

---
Experimentation:
  Overview: experimentation/index.md
  home AB:
    Overview: experimentation/home-ab/index.md
    Metrics: experimentation/home-ab/metricas/index.md
    Adtional Metrics:
      User Frequency: experimentation/home-ab/metricas/frequencia.md
      MVT: experimentation/home-ab/metricas/mvt.md
  home MAB:
    Overview: experimentation/home-mab/index.md
    Criação Standard MAB: experimentation/home-mab/criacao-experimento.md
  Experimentation: []

你可以用yqAdtional Metrics块中插入新行:

yq -i '.Experimentation.["home AB"].["Adtional Metrics"] += {"INSERT": "NEW_LINE_INCREMENT"}' mkdocs.yml

相关问题