0

I am new to command line scripting. I just want to copy text starting from a particular string and ending with another string. How can I achieive that using sed or grep or any other way.

eg:

-----CompilerOutput:-stderr----------
Assets/Editor/AutoBuild1.cs(12,16): error CS1001: Unexpected symbol `(', expecting identifier
Assets/Editor/AutoBuild1.cs(12,32): error CS1026: Unexpected symbol `,', expecting `)'
Assets/Editor/AutoBuild1.cs(12,78): error CS1026: Unexpected symbol `,', expecting `)'
Assets/Editor/AutoBuild1.cs(12,99): error CS1525: Unexpected symbol `,', expecting `;' or `}'
Assets/Editor/AutoBuild1.cs(12,125): error CS1525: Unexpected symbol `)', expecting `;' or `}'
-----EndCompilerOutput---------------

Here I want to copy text from -----CompilerOutput:-stderr---------- till -----EndCompilerOutput--------------- from the error log which is saved to log.txt

Thanks in advance.

Nabeel K
  • 5,938
  • 11
  • 38
  • 68

1 Answers1

1

Following simple sed may help you in same.

sed -n '/CompilerOutput:-stderr/,/EndCompilerOutput/p' Input_file

Explanation: Using sed here with -n option which will STOP by default printing of the lines. Then by doing /CompilerOutput:-stderr/,/EndCompilerOutput/ this I am searching strings on a line from string /CompilerOutput:-stderr to EndCompilerOutput if this condition is TRUE then using p option will print those lines then.

RavinderSingh13
  • 130,504
  • 14
  • 57
  • 93