Re: [Hampshire] File slicing

Top Page

Reply to this message
Author: Victor Churchill
Date:  
To: Hampshire LUG Discussion List
Subject: Re: [Hampshire] File slicing
On 19/02/07, John Hunt <johnrhunt@???> wrote:
> Hi,
>
> I have a huge file which contains a mysqldump of all the databases on
> a server, I'm after just a specific part of it, that is, the table
> data for phpbb within a database called rgse.
>
> The file is wayy too big for the likes of emacs etc, so I was
> wondering if anyone knows how to crop off the everything until a line
> with CREATE DATABASE rgse, and everything after CREATE DATABASE?
>
> Cheers,
> John.


Hi John,

I'm sure there was an example of exactly this on the sed manpages but
it's been so long since I did sed that I was too rusty.

I just tried a perl one-liner as follows:

given /tmp/foo:
----
1
2
3
start
4
5
end
6
7
----

then

victor@ss07:~$ perl -n -e '/start/&&$p++;/end/&&$p--;print if $p;' < /tmp/foo
start
4
5
victor@ss07:~$

Needs to be single quotes to stop the shell messing about with the $p.

No doubt it can be done almost as compactly in awk as well.
hope that helps,
victor