AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / unix / 问题

问题[yaml](unix)

Martin Hope
Rang's
Asked: 2023-07-28 14:23:46 +0800 CST

bash 使用 sed/awk 从文件中获取所需行

  • 5

文件内容如下:

Text1:
    text_1: Text1 text_1
    text_2:
    - text
    - file1:\\
    - file2:\\
Text2:
    text_1: Text2 text_1
    text_2:
    - text
    - file3:\\
Text3:
    etc

输出:打印给定 Textn 的“file:\”条目。知道如何在 Linux 中使用 sed/awk 命令来实现这一点。

示例:test.txt 文件内容如下:

$ cat test.txt 
Text1:
    text_1: Text1 text_1
    text_2:
    - text
    - file1:\\
    - file2:\\
Text2:
    text_1: Text2 text1
    text_2:
    - text
    - file3:\\
Text3:
    etc

按照建议尝试下面的 grep 命令,它会打印 test.txt 文件中的所有“file:\”条目。对于“Text1:”匹配,我需要的只是 file1:\ 和 file2:\ 作为输出,对于“Text2:”仅匹配 file3:\。

yaml
  • 1 个回答
  • 56 Views
Martin Hope
malat
Asked: 2023-06-28 19:54:08 +0800 CST

如何将包含特殊字符的长命令拆分为多行命令?

  • 5

我一直在阅读 gitlab 的文档:

  • https://docs.gitlab.com/ee/ci/yaml/script.html#split-long-commands

就我而言,我有一个特殊字符(冒号“:”),所以我也阅读了:

  • https://docs.gitlab.com/ee/ci/yaml/script.html#use-special-characters-with-script

现在我的问题是:如何将两者结合起来?

一方面我有(参考):

job name:
  script:
    - |
      for file in *; do
        echo "$file";
        echo "${REPO}/${file}";
      done

另一方面,我有(参考):

  script:
    - 'for file in *; do curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file "${file}" "${REPO}/${file}"; done'

我如何将两者结合起来?长期解决方案是将for循环中的错误处理为(ref):

    - 'http_code=$(curl -o /dev/null -s -w "%{http_code}" --header "JOB-TOKEN: $CI_JOB_TOKEN" --upload-file "$file" "${REPO}/${file}")'
    - if [ $http_code -ne 201 ]; then echo "Upload failed: terminating" && false; fi;
yaml
  • 1 个回答
  • 46 Views
Martin Hope
Mridul Gain
Asked: 2022-06-20 23:58:17 +0800 CST

确定 IP 地址并在单个命令中编辑配置

  • 0

我正在尝试确定 docker 容器的内部 IP 并将其用作 yaml 配置文件中的值。确定IP的命令是;

docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' controller-control-plane

而且,为了就地编辑配置,我正在使用;

yq -i '.kubeslice.controller.endpoint = "https://<output_from_previous_command>:6443"'  values.yaml

现在,如果我想使用第一个命令作为这样的参数;

yq '.kubeslice.controller.endpoint = "https://$(docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' controller-control-plane):6443"'  values.yaml

然后输出没有按预期进行。

kubeslice:
  controller:
    loglevel: info
    rbacResourcePrefix: kubeslice-rbac
    projectnsPrefix: kubeslice
    endpoint: https://$(docker inspect -f {{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}} controller-control-plane):6443

如何正确执行此操作,以便端点获得正确的 IP 值而不是命令字符串?

yaml
  • 3 个回答
  • 34 Views
Martin Hope
Jackson
Asked: 2022-02-21 10:15:03 +0800 CST

如何从 YAML 文件中提取几个 IP 地址

  • 3

masters/hosts我有这个文件,如果他们的行没有被注释,我想选择该部分下的所有 IP 地址。我试过这个sed 's/.*\ \([0-9\.]\+\).*/\1/g',但它没有用。

metal:
  children:
    masters:
      hosts:
        dev0: {ansible_host: 172.168.1.10}
        # dev1: {ansible_host: 185.168.1.11}
        # dev2: {ansible_host: 142.168.1.12}
    workers:
      hosts: {}
        # dev3: {ansible_host: 172.168.1.13}

yaml
  • 2 个回答
  • 903 Views
Martin Hope
kshnkvn
Asked: 2020-02-08 07:07:46 +0800 CST

如何在 Dockerfile 或 shell 中编辑 yaml 文件?

  • 0

在 Dockerfile 中,我从 curl 上传了一个配置文件,然后我需要对其进行一些编辑,这是一个示例结构:

client:
  ...
server:
  applicationConnectors:
  - type: http
    port: 8989
    # for security reasons bind to localhost
    bindHost: localhost
  requestLog:
      appenders: []
  adminConnectors:
  - type: http
    port: 8990
    bindHost: localhost

我需要编辑这两个bindHost参数,如果我可以在 期间将它们的值作为参数传递,那将是可取的docker build,但我似乎没有在 Internet 或文档中找到任何内容。

docker yaml
  • 2 个回答
  • 3864 Views
Martin Hope
PersianGulf
Asked: 2019-12-08 09:54:33 +0800 CST

将 YAML 转换为 JSON 时出错:yaml:第 10 行:未找到预期的密钥

  • 0

我有以下yaml文件:

---
apiVersion: v1
kind: pod
metadata:
    name: Tesing_for_Image_pull -----------> 1
    spec:
        containers:
        - name: mysql ------------------------> 2
          image: mysql ----------> 3
          imagePullPolicy: Always ------------->4
          command: ["echo", "SUCCESS"]  -------------------> 5

运行后kubectl create -f my_yaml.yaml出现以下错误:

error: error converting YAML to JSON: yaml: line 10: did not find expected key

更新:yamllint我收到以下错误:

root@debian:~# yamllint my_yaml.yaml
my_yaml.yaml
  8:9       error    wrong indentation: expected 12 but found 8  (indentation)
  11:41     error    syntax error: expected <block end>, but found '<scalar>'

我的问题在哪里,我该如何解决?

kubernetes yaml
  • 1 个回答
  • 30642 Views
Martin Hope
neurino
Asked: 2019-09-05 05:49:48 +0800 CST

导出从 YAML 文本文件解析的环境变量 [重复]

  • 0
这个问题在这里已经有了答案:
在 bash 中,在管道未设置值后读取 2 个答案
3年前关闭。

我在 YAML 文件中声明了一些环境变量,例如:

runtime: python37

env_variables:
  API_URL: 'https://fake.api.com/'
  API_USERNAME: '[email protected]'
  API_PASSWORD: 'Passwooord'

我想用脚本将这些导出到环境变量,我可以回显正确的语法,但我仍然无法导出它们。

sed -nr '/env_variables:/,$ s/  ([A-Z_]+): (.*)/\1=\2/ p' app.yaml | while read assign; do echo $assign; done

这与我的情况不同,因为在我的情况下,变量名也通过管道传递。

environment-variables yaml
  • 1 个回答
  • 7897 Views
Martin Hope
Øistein Søvik
Asked: 2018-07-20 10:03:19 +0800 CST

查找不正确的 YAML 标头

  • 3

我正在尝试确定我的项目中哪些文件的标头不正确。文件都是这样开始的

---
header:
.
.
.
title: 
some header:
.
.
.
more headers:
level: 
.
.
.
---

在哪里 。. . 只代表更多的标题。标题不包含缩进。使用以下表达式,我已经能够从每个文件中提取 YAML 标头。

grep -Przo --include=\*.md "^---(.|\n)*?---" .

现在我想列出不正确的 YAML 标头。

  • 每个 YAML 标头都必须有一个title: some text
  • 每个 YAML 标头都必须有language: [a-z]{2}
  • 它必须包含一个external: .*或author: .*。
  • title:、level:和external:的位置language:各不相同。

我试着做类似的事情

grep -L --include=\*.md -e "external: .*" -e "author: .* ."

然而,这样做的问题是它会搜索整个文件,而不仅仅是 YAML 标头。所以我想解决上述问题归结为如何将我之前搜索的 YAML 标头结果再次输入 grep。我试过了

grep -Przo --include=\*.md "^---(.|\n)*?---" . | xargs -0 grep "title:";

然而,这给了我一个错误“没有这样的文件或目录”,所以我有点不确定如何继续。

例子:

---
title: Rull-en-ball
level: 1
author: Transkribert og oversatt fra [Unity3D](http://unity3d.com)
translator: Bjørn Fjukstad
license: Oversatt fra [unity3d.com](https://unity3d.com/learn/tutorials/projects/roll-ball-tutorial)
language: nb
---

正确的 YAML,有作者、语言和标题。

---
title: Mini Golf
level: 2
language: en
external: http://appinventor.mit.edu/explore/ai2/minigolf.html
---

正确的 YAML,有标题、语言和外部而不是作者。

---
title: 'Stjerner og galakser'
level: 2
logo: ../../assets/img/ccuk_logo.png
license: '[Code Club World Limited Terms of Service](https://github.com/CodeClub/scratch-curriculum/blob/master/LICENSE.md)'
translator: 'Ole Andreas Ramsdal'
language: nb
---

YAML 标头不正确,缺少作者。

grep yaml
  • 2 个回答
  • 322 Views
Martin Hope
Or Weinberger
Asked: 2018-03-22 01:55:48 +0800 CST

使用 sed 替换多行

  • 2

我正在尝试替换 YAML 文件的以下部分:

  ssl:
    enabled: false

读书

  ssl:
    enabled: true

我试过这个,但失败了:sed -i s/ssl:\n enabled: false/ssl:\n enabled: true/g

sed yaml
  • 3 个回答
  • 14094 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    模块 i915 可能缺少固件 /lib/firmware/i915/*

    • 3 个回答
  • Marko Smith

    无法获取 jessie backports 存储库

    • 4 个回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    user12345 无法获取 jessie backports 存储库 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl 为什么大多数 systemd 示例都包含 WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve