LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Copy lines starting and ending with specific pattern from multiple files to a file (https://www.linuxquestions.org/questions/linux-newbie-8/copy-lines-starting-and-ending-with-specific-pattern-from-multiple-files-to-a-file-893981/)

ssn 07-27-2011 01:22 AM

Copy lines starting and ending with specific pattern from multiple files to a file
 
Hi,

A function by name abc is called in many files. I want to copy all the lines with the function call to an output file.
A simple grep on function name doesn't help me as the function call is spanning across multiple lines as follows:

abc(parameter1,
parameter2,
parameter3);

So I want to copy all the three lines (till semicolon) to the output file.

The problem is because there are more than 200 calls for the same function and I cannot do it manually :(

Thanks in advance.

druuna 07-27-2011 03:43 AM

Hi,

It is not clear from your post if the function(s) you are looking for always span 3 lines.

Maybe one of these will do what you want:
Code:

always 3 lines
grep "^.*(" -A2 infile > outfile

Varying lines
sed -n '/.*(/,/);/p' infile > outfile

Hope this helps.

grail 07-27-2011 10:44 AM

So how about:
Code:

awk 'BEGIN{ORS=RS=";"}/abc\(/' file


All times are GMT -5. The time now is 11:45 AM.