ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Solved Help with sed insert from file

    IT Discussion
    1
    2
    122
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • IRJI
      IRJ
      last edited by

      I am trying to insert the contents of a text file into a configuration file using sed

      sed -i 's/string_in_file/r /home/user/textfile' -r /dir/conf.file

      So I want to replace string_in_file with the contents of /home/user/textfile

      Help 🙂

      1 Reply Last reply Reply Quote 1
      • IRJI
        IRJ
        last edited by

        Found the answer here:
        https://unix.stackexchange.com/questions/32908/how-to-insert-the-content-of-a-file-into-another-file-before-a-pattern-marker

        sed 's/CHANGEME/$x/g' origfile | x="$(<file2insert)" envsubst '$x' > newfile
        

        This will replace every CHANGEME occurence in origfile with the content of file2insert. Remove last g from sed to replace only the first occurrence of CHANGEME.

        1 Reply Last reply Reply Quote 4
        • 1 / 1
        • First post
          Last post