-1

In a sed command I need to essentially add 2+ space to each line copied from the output to the input and then delete the last line from the output when input. This is what I have:

sed -i -e '/PLACEHOLDER/ r TestOutput.txt' -e s/PLACEHOLDER// SQLInput.txt

The sed command already imports from the output to the input and deletes PLACEHOLDER, but I can't figure out how to get it to add 2 spaces to each line that was input from the output. Keep in mind, the input would also contain other variables and functions that I don't want to change.

Output:

WORD
WORD
WORD
WORD

Input:

PLACEHOLDER

Expected input after sed command:

  WORD
  WORD
  WORD
  WORD

closed as unclear what you're asking by αғsнιη, Stephen Rauch, Scott, Romeo Ninov, dr01 Aug 21 '17 at 7:30

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Maybe prepare a copy of test output that already has the spaces? – Jeff Schaller Aug 21 '17 at 2:26
  • 1
    The usage of "input" and "output" in this question is really confusing. – Kusalananda Aug 21 '17 at 7:06
  • sed doesn't process files read with the r command, so the only way to do this with a single sed command would be to give both files as arguments; the first will placed to the hold space with added whitespaces, than in the second the placeholder gets replaced by the pattern space. This is easy if there is some method to identify the end of the TestOutput.txt or the beginning of the input file. So we need more information of the actual file contents. – Philippos Aug 21 '17 at 7:32
1

I am not clear on exactly where you want to add space but I guess that may help you:

sed -i -e '/PLACEHOLDER/ r TestOutput.txt' -e 's/PLACEHOLDER//;s/^/  /' SQLInput.txt

the ^ is a start line anchor, so the statement s/^/ / is basically just adding two space at the beginning of any lines.

  • 1
    Wrong. The file read with r command is directed to the output without going through the pattern space, so it will not get processed. – Philippos Aug 21 '17 at 7:26

Not the answer you're looking for? Browse other questions tagged or ask your own question.