only the inserts

rgb192
rgb192 used Ask the Experts™
on
I have a .sql dump file where some inserts are on multiple lines

I know that every insert line begins with 'insert' and ends with ';'

how can I get only the inserts
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
RobOwner (Aidellio)
Most Valuable Expert 2015

Commented:
Are you looking for a regular expression?  

^INSERT[^;]+

not sure it will work for multiple lines though

Author

Commented:
I dont understand
do i use preg_replace or something else
Owner (Aidellio)
Most Valuable Expert 2015
Commented:
oh ok... you're parsing the file with php.  In that case

preg_match_all("/^INSERT[^;]+/i",...);
11/26 Forrester Webinar: Savings for Enterprise

How can your organization benefit from savings just by replacing your legacy backup solutions with Acronis' #CyberProtection? Join Forrester's Joe Branca and Ryan Davis from Acronis live as they explain how you can too.

Author

Commented:
preg_match_all("/^INSERT[^;]+/i",...)

what do I put around this statement to get data from infile and send to outfile

Commented:
$my_text = file_get_contents('FILENAME');
preg_match_all('/INSERT[^;*];/si',$my_text,$matches);
echo '<pre>';
print_r($matches);
echo '</pre>';
RobOwner (Aidellio)
Most Valuable Expert 2015

Commented:
As @virmaior has shown, read the file contents into a string variable and then search it using a regular expression
Commented:
my regex was off... this should be correct:
preg_match_all('/INSERT[^;]*;/si',$my_text,$matches);

Author

Commented:
thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial