“SED Zastąp pojedynczą linię na wiele linii” Kod odpowiedzi

SED Zastąp pojedynczą linię na wiele linii

wget -O metallb-values.yml https://raw.githubusercontent.com/bitnami/charts/master/bitnami/metallb/values.yaml
cat > /tmp/0 <<EOF 
configInline:
  # The address-pools section lists the IP addresses that MetalLB is
  # allowed to allocate, along with settings for how to advertise
  # those addresses over BGP once assigned. You can have as many
  # address pools as you want.
  address-pools:
  - # A name for the address pool. Services can request allocation
    # from a specific address pool using this name, by listing this
    # name under the 'metallb.universe.tf/address-pool' annotation.
    name: generic-cluster-pool
    # Protocol can be used to select how the announcement is done.
    # Supported values are bgp and layer2.
    protocol: layer2
    # A list of IP address ranges over which MetalLB has
    # authority. You can list multiple ranges in a single pool, they
    # will all share the same settings. Each range can be either a
    # CIDR prefix, or an explicit start-end range of IPs.
    addresses:
    - 192.xxx.xxx.xx1-192.xxx.xxx.xx5
EOF
sed -i -e "/configInline: {}/r /tmp/0" -e "//d" metallb-values.yml
DreamCoder

SED Zastąp pojedynczą linię na wiele linii

echo ${DATA} > temp.txt    
sed -i -e "/_data_/r temp.txt" -e "//d" mail.tpl
DreamCoder

SED Zastąp pojedynczą linię na wiele linii

DATA="$(cat whatever)"
ESCAPED_DATA="$(echo "${DATA}" | sed ':a;N;$!ba;s/\n/\\n/g' | sed 's/\$/\\$/g')"

Then you can use ${ESCAPED_DATA} in sed:

cat input | sed 's/one liner/'"${ESCAPED_DATA}"'/' > output 
DreamCoder

SED Zastąp pojedynczą linię na wiele linii

DATA="a
b
c"

ESCAPED=$(echo "${DATA}" | sed '$!s@$@\\@g')
echo "${ESCAPED}" 
a\
b\
c

sed "s/pattern/${ESCAPED}/" file
DreamCoder

SED Zastąp pojedynczą linię na wiele linii

$ echo test | sed 's/test/line\
> line'
line
line
DreamCoder

Odpowiedzi podobne do “SED Zastąp pojedynczą linię na wiele linii”

Pytania podobne do “SED Zastąp pojedynczą linię na wiele linii”

Więcej pokrewnych odpowiedzi na “SED Zastąp pojedynczą linię na wiele linii” w Shell/Bash

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu