I need to use the patterns above to grep a variable with multiple lines inside. the variable with the multiline content is called "nidgrps", content of the variable is below
When you have code that isn't working, it always helps us help you if you show us the exact diagnostics that are printed when you run your code, show us any other output that you get, and tell us what operating system and shell you're using.
Assuming that the variable nidgrps has been initialized to the name of the file containing the data you want to process, that the variable rptfile has been initialized to the string rptfile , that you are trying to perform a case-insensitive match, that you want to add the matched text to the end of the current contents of the file named rptfile rather than replace its existing contents, and that you are using a shell that uses basic Bourne shell syntax; you would have succeeded if you had quoted your variables appropriately.
But, in addition to that, there is no need for cat in this pipeline; using it just slows you down and consumes system resources needlessly. Try:
Consider the following... it works. I'm thinking that just like my case below your nidgrps maybe is a string inside a variable?? So you'd use echo instead of cat??