Replace string with multiline file content

Emetrop

I need to replace string SALT in a file with content of another file. Problem is that the input file has multilines. I tried something like this in my bash script:

SALT=`cat salt.txt`;
sed "s/SALT/$SALT/" wp-config.php > result.txt

It work's fine when the salt.txt is single line, but if there are more lines it fails. I've read that it could do PERL. But I don't know how. Could you help me?

Sylvain Pineau

Another perl way:

perl -pe 's/SALT/`cat salt.txt`/e' wp-config.php > result.txt

The key here is the /e regexp option allowing us to use a perl command result as a substitution string.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Replace string with multiline file content

From Dev

Replace a multiline string with the content of a file.txt

From Dev

Replace text in file with multiline string

From Dev

Replace a string by the content of a file

From Dev

Replace multiline string with js

From Dev

replace in multiline - refer to content for replacement

From Dev

javascript replace multiline string with multiline string

From Dev

Groovy replacing place holders of file content similar to multiline-string

From Dev

Groovy replacing place holders of file content similar to multiline-string

From Dev

Replace string content between quotes in file

From Dev

Find and replace string spanned multiline

From Dev

Echo multiline string into file bash

From Dev

Search for multiline String in a text file

From Dev

Read file, replace string and create a new one with all content

From Dev

Replace one string with the content pulled from other file

From Dev

Replace string between two words with the content of another text file

From Dev

Replace multiline string in all files in terminal

From Dev

Multiline string replace inside markup tag

From Dev

Search and replace all lines in a multiline string

From Dev

Replace a multiline string with pattern using sed command

From Dev

bash replace multiline text in file, with pattern

From Dev

multiline regex match string replacement on large file

From Dev

multiline regex match string replacement on large file

From Dev

How to write a multiline string to a file in Bash

From Dev

Replace content of one string with another?

From Dev

replace string content using .* in java

From Dev

Replace content with square braces in string

From Dev

Replace first nth occurences of string1 by string2 after string3, within a file (i.e multiline pattern)

From Dev

Replace content inte a PDF File

Related Related

  1. 1

    Replace string with multiline file content

  2. 2

    Replace a multiline string with the content of a file.txt

  3. 3

    Replace text in file with multiline string

  4. 4

    Replace a string by the content of a file

  5. 5

    Replace multiline string with js

  6. 6

    replace in multiline - refer to content for replacement

  7. 7

    javascript replace multiline string with multiline string

  8. 8

    Groovy replacing place holders of file content similar to multiline-string

  9. 9

    Groovy replacing place holders of file content similar to multiline-string

  10. 10

    Replace string content between quotes in file

  11. 11

    Find and replace string spanned multiline

  12. 12

    Echo multiline string into file bash

  13. 13

    Search for multiline String in a text file

  14. 14

    Read file, replace string and create a new one with all content

  15. 15

    Replace one string with the content pulled from other file

  16. 16

    Replace string between two words with the content of another text file

  17. 17

    Replace multiline string in all files in terminal

  18. 18

    Multiline string replace inside markup tag

  19. 19

    Search and replace all lines in a multiline string

  20. 20

    Replace a multiline string with pattern using sed command

  21. 21

    bash replace multiline text in file, with pattern

  22. 22

    multiline regex match string replacement on large file

  23. 23

    multiline regex match string replacement on large file

  24. 24

    How to write a multiline string to a file in Bash

  25. 25

    Replace content of one string with another?

  26. 26

    replace string content using .* in java

  27. 27

    Replace content with square braces in string

  28. 28

    Replace first nth occurences of string1 by string2 after string3, within a file (i.e multiline pattern)

  29. 29

    Replace content inte a PDF File

HotTag

Archive