0

It's really difficult to explain why I need this- so I'm just going to describe what I need.

Basically, I need to use sed (or awk, or whatever) to add a sed line to a specific spot inside a file. Namely, I have to find where in the file it says peer.i and starts a new line, and insert in the subsequent line my sed command.

This is my attempt:

sed -i "s/peer\.i\n/peer\.i\n\tsed -i 's/is_array/is_an_array/g' path_to_inside_file/g" path_to_outside_file

This didn't work, so I also tried this:

sed -i "s/peer\.i\n/peer\.i\n\tsed -i 's\/is_array\/is_an_array\/g' path_to_inside_file/g" path_to_outside_file

I'm not really sure why this isn't working, and any help/explanation would be appreciated.

John Rouhana
  • 538
  • 3
  • 15
  • 2
    [This answer](https://stackoverflow.com/a/15559399/7389264) should help you if you're on Linux (or are otherwise using GNU sed). [This answer](https://stackoverflow.com/a/25306308/7389264) to the same question should fit if you're using any other POSIX-compliant sed implementation. The reason your attempts didn't work is because sed operates on lines—the `s` command can't replace newlines. – jirassimok Aug 01 '19 at 23:03
  • That's awesome- thanks for the heads-up. I am on a Linux and was able to find a non-sed solution to my specific problem, but unfortunately that solution is bound by line number, so I'll be trying to make this work still. – John Rouhana Aug 01 '19 at 23:43
  • The basic answer is that you use the `a` command to add new lines, not `s`. – Barmar Aug 01 '19 at 23:54

0 Answers0