Replace string in one file with contents of a second file

Posted by jag7720 on Stack Overflow See other posts from Stack Overflow or by jag7720
Published on 2012-11-20T22:53:52Z Indexed on 2012/11/20 22:59 UTC
Read the original article Hit count: 367

Filed under:
|

I have two files:

  • fileA:

    date >> /root/kvno.out
    kvno serverXXX\$ >> /root/kvno.out
    
  • fileB:

    foobar
    

I need to create a new file, fileC, with the same contents as fileA, except with the string XXX being replaced with the contents of fileB:

date >> /root/kvno.out
kvno serverfoobar\$ >> /root/kvno.out

I'd like to do this using sed.

I tried some of the examples I found but I only get the contents of fileB in fileC.

© Stack Overflow or respective owner

Related posts about bash

Related posts about sed