sed:パターンの後に一致する行を移動しますか?

sed:パターンの後に一致する行を移動しますか?

設定ファイルがあります.drone.yml

workspace:
  base: x
  path: y

pipeline:
  import-groups-check:
    pull: true

  static-check:
    pull: true

  build:
    image: golang:1.9.0

  publish:
    image: plugins/docker:1.13

  validate-merge-request:
    pull: true

  notify-youtrack:
    pull: true

validate-merge-request私が望むのは、最初のステップに進むことです。

workspace:
  base: x
  path: y

pipeline:
  validate-merge-request:
    pull: true

  import-groups-check:
    pull: true

  static-check:
    pull: true

  build:
    image: golang:1.9.0

  publish:
    image: plugins/docker:1.13

  notify-youtrack:
    pull: true

次の方法を使用してステップを抽出できますvalidate-merge-request

sed -e '/validate-merge-request/,/^ *$/!{H;d;}'

それからどのように移動できますかpipeline:

ベストアンサー1

フロント:

sed -e '
  # From first line to pipeline:,just print and start next cycle
  1,/^pipeline:$/b
  # With all lines outside validate-merge-request block, push to hold space,
  # delete them and start next cycle
  # On last line, exchange hold space to pattern space, print pattern space
  /validate-merge-request/,/^$/!{
    H
    ${
      x
      s/\n//
      p
    }
    d
  }' <file

pipeline:ブロックの後ろとブロックの内側ではないすべての行はvalidate-merge-requestメモリに保持されます。

おすすめ記事