0

I have an text file named answer.txt. And i'm trying to read the contents from a file and trying to insert in the below yaml file (above 'kind:')

For that, I'm reading the file and assigning to a variable.
file= 'cat answer.txt'

If, I print this using echo, echo $file I can able to see the contents.

But, when i try to insert this in SED command, the actual variable itself is getting inserted but not the actual contents. I'm not sure, what i'm doing wrong here.

Command - sed '/kind/i $file' input

Yaml file name - input

apiVersion: v1
data:
  Corefile: |
    .:53 {
        errors
        health
        kubernetes cluster.in-addr.arpa ip6.arpa {
           pods insecure
           upstream
           fallthrough in-addr.arpa ip6.arpa
           ttl 30
        }
        prometheus :1020
        forward . /etc/resolv.conf
        cache 30
        loop
        reload
        loadbalance
    }
kind: ConfigMap
metadata:
  creationTimestamp: "2020-01-24T15:19:51Z"
  name: core
  namespace: system
  resourceVersion: "166"
  selfLink: /api/v1/system/configmaps/core
  uid: b80b35ad-8718-4e88-8asbef-bceb289d50ee


After applying SED command,

apiVersion: v1
    data:
      Corefile: |
        .:53 {
            errors
            health
            kubernetes cluster.in-addr.arpa ip6.arpa {
               pods insecure
               upstream
               fallthrough in-addr.arpa ip6.arpa
               ttl 30
            }
            prometheus :1020
            forward . /etc/resolv.conf
            cache 30
            loop
            reload
            loadbalance
        }
    $file
    kind: ConfigMap
    metadata:
      creationTimestamp: "2020-01-24T15:19:51Z"
      name: core
      namespace: system
      resourceVersion: "166"
      selfLink: /api/v1/system/configmaps/core
      uid: b80b35ad-8718-4e88-8asbef-bceb289d50ee

Could some one please correct me as i'm a beginner?
Thanks in advance

Operating System - MAC

Kent
  • 189,393
  • 32
  • 233
  • 301
Aishu
  • 1,310
  • 6
  • 28
  • 52

0 Answers0