LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-27-2011, 01:22 AM   #1
ssn
LQ Newbie
 
Registered: Jul 2011
Posts: 4

Rep: Reputation: Disabled
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.
 
Old 07-27-2011, 03:43 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
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.

Last edited by druuna; 07-27-2011 at 03:49 AM.
 
Old 07-27-2011, 10:44 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
So how about:
Code:
awk 'BEGIN{ORS=RS=";"}/abc\(/' file
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] copy lines from multiple files to one file using sed -w cruzdelsur Programming 12 08-26-2010 08:24 AM
deleting lines from a file with specific pattern using AWK gandhigaurav1986 Programming 12 06-08-2010 02:08 AM
[SOLVED] Replace pattern in specific lines and column with AWK cgcamal Programming 10 04-26-2010 01:11 AM
AWK/SED Multiple pattern matching over multiple lines issue GigerMalmensteen Programming 15 12-03-2006 05:08 PM
Removing Text in a single line starting with one pattern ending on another mgwheeler Programming 13 08-03-2004 04:36 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration