Find the answer to your Linux question:
Results 1 to 2 of 2
i know this can be done, i just can't figure it out (i'm good with RegEx's, but bad with sed). i need to insert file2 into file1 after finding PATTERN ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Aug 2006
    Location
    oklahoma
    Posts
    12

    [SOLVED] insert file after a line with sed or awk?


    i know this can be done, i just can't figure it out (i'm good with RegEx's, but bad with sed).

    i need to insert file2 into file1 after finding PATTERN

    ex:
    file1 -
    abcdef
    ghijklm
    nopqrs

    file2 -
    tuvwxzy
    yzxwvut

    so say my pattern is "ghij". i would need to insert file2 into the line after that pattern is found.

    i know this can be done with sed, the 'r' option, and somehow designating an 'a' for append, but i just don't understand the order/syntax for that.

    any help would be greatly appreciated. thank you.

  2. #2
    Just Joined!
    Join Date
    Aug 2006
    Location
    oklahoma
    Posts
    12
    so i just tried a bunch of different things, and ran into the solution.

    sed -i '/MYREGEXPATTERN/ r myfiletoinsert.txt' mymainfile.txt

    easy enough. would be nice if you could do this with a case insensitive search, but this will do. you can just add the insensitive regex if you wanted.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •