Discussion:
Need help please
marvin carandang
2009-07-29 12:03:50 UTC
Permalink
Hello Nedit Experts,

I have a long list of digital pattern and would like to delete certain groups of texts in between. I attached a snap-shot below. ( I just changed the content due to confidentiality reasons):

------------------------------------------------------------------
Page 1 abcdefassdsd,msdskdskskds
njsdsdjskd
...
...
..
....
.....
                                                                                                                                 Example
      < Digital Data>

Page 2 abcdefassdsd,msdskdskskds
njsdsdjskd
...
...
..
....
.....
                                                                                                                                 Example      
    <Digital Data>

...and so on....
-------------------------------------------------------


I want to delete all characters starting from the "space" after the page number until the word "Example". I short, I need the resulting data to be like this:
------------------------------------
Page 1

        < Digital Data>

Page 2

       < Digital Data>

Page 3

... and so on
--------------------------------------
This is thousands of pages long but the pattern is just the same. How do I do that? Thanks for the help!!!

//electron
--
NEdit Discuss mailing list - Discuss-***@public.gmane.org
http://www.nedit.org/mailman/listinfo/discuss
Michael Smith
2009-07-29 12:21:19 UTC
Permalink
On Wed, 29 Jul 2009 05:03:50 -0700 (PDT)
Post by marvin carandang
Hello Nedit Experts,
------------------------------------------------------------------
Page 1 abcdefassdsd,msdskdskskds
njsdsdjskd
...
...
..
....
.....
                                                                                                                                 Example
      < Digital Data>
Page 2 abcdefassdsd,msdskdskskds
njsdsdjskd
...
...
..
....
.....
                                                                                                                                 Example      
    <Digital Data>
...and so on....
-------------------------------------------------------
------------------------------------
Page 1
        < Digital Data>
Page 2
       < Digital Data>
Page 3
... and so on
--------------------------------------
This is thousands of pages long but the pattern is just the same. How do I do that? Thanks for the help!!!
//electron
Better to write an awk program.

/^Page.*$/ {
skip=1
}

/^.*Example.*$/ {
skip=0
}

{
if(skip != 0)
{
print
}
}


This is just an indication of what you can do. It won't work properly up front. If you can send me some actual data I might be able to do a better job with 10 minutes of hacking or so.
--
Michael Smith
Network Applications
www.netapps.com.au | +61 (0) 416 062 898
Web Hosting | Internet Services
intertwingled
2009-07-29 13:57:47 UTC
Permalink
Better to do it in Perl!
Post by Michael Smith
On Wed, 29 Jul 2009 05:03:50 -0700 (PDT)
Post by marvin carandang
Hello Nedit Experts,
------------------------------------------------------------------
Page 1 abcdefassdsd,msdskdskskds
njsdsdjskd
...
...
..
....
.....
Example
< Digital Data>
Page 2 abcdefassdsd,msdskdskskds
njsdsdjskd
...
...
..
....
.....
Example
<Digital Data>
...and so on....
-------------------------------------------------------
------------------------------------
Page 1
< Digital Data>
Page 2
< Digital Data>
Page 3
... and so on
--------------------------------------
This is thousands of pages long but the pattern is just the same. How do I do that? Thanks for the help!!!
//electron
Better to write an awk program.
/^Page.*$/ {
skip=1
}
/^.*Example.*$/ {
skip=0
}
{
if(skip != 0)
{
print
}
}
This is just an indication of what you can do. It won't work properly up front. If you can send me some actual data I might be able to do a better job with 10 minutes of hacking or so.
--
I always have coffee when I watch radar!
--
NEdit Discuss mailing list - Discuss-***@public.gmane.org
http://www.nedit.org/mailman/listinfo/discuss
Offer Kaye
2009-07-29 14:23:50 UTC
Permalink
Post by marvin carandang
Hello Nedit Experts,
Since nedit's find-replace dialog can use regular expressions it is
quite powerful. If you type the following in the Find field of the
Replace dialog:

(Page\s+\d+).+\n(?n.+?)Example\s*\n

and the following in the Replace field:

\1\n


This should do the job. Of course you need to check the "Regular
Expression" checkbox before hitting the "Window" button.

To understand the above please see NEdit's regular-expressions
documentation. In any case your question is not really an "NEdit"
question, per-se, but more of a regexp-related question. For example
the following Perl one-liner, run from the Unix command-line, does the
job in nearly the same manner - or at least it should :-)

perl -pi.bak -0 -e's/(Page\s+\d+).+?Example\s*\n/$1\n/sg' <input_file>

This will replace the input_file contents and save the original in a
backup input_file.bak.

Cheers,
--
Offer Kaye
--
NEdit Discuss mailing list - Discuss-***@public.gmane.org
http://www.nedit.org/mailman/listinfo/discuss
marvin carandang
2009-07-29 19:13:08 UTC
Permalink
Hi Kaye,

Thank you very much. I'll try this out.

Regards,




________________________________
From: Offer Kaye <***@gmail.com>
To: General NEdit discussion list <discuss-***@public.gmane.org>
Sent: Wednesday, July 29, 2009 4:23:50 PM
Subject: Re: Need help please
Post by marvin carandang
Hello Nedit Experts,
Since nedit's find-replace dialog can use regular expressions it is
quite powerful. If you type the following in the Find field of the
Replace dialog:

(Page\s+\d+).+\n(?n.+?)Example\s*\n

and the following in the Replace field:

\1\n


This should do the job. Of course you need to check the "Regular
Expression" checkbox before hitting the "Window" button.

To understand the above please see NEdit's regular-expressions
documentation. In any case your question is not really an "NEdit"
question, per-se, but more of a regexp-related question. For example
the following Perl one-liner, run from the Unix command-line, does the
job in nearly the same manner - or at least it should :-)

perl -pi.bak -0 -e's/(Page\s+\d+).+?Example\s*\n/$1\n/sg' <input_file>

This will replace the input_file contents and save the original in a
backup input_file.bak.

Cheers,
--
Offer Kaye
--
NEdit Discuss mailing list - Discuss-***@public.gmane.org
http://www.nedit.org/mailman/listinfo/discuss
--
NEdit Discuss mailing list - Discuss-***@public.gmane.org
http://www.nedit.org/mailman/listinfo/discuss
Andrew Hood
2009-07-29 22:04:34 UTC
Permalink
Post by Offer Kaye
Post by marvin carandang
Hello Nedit Experts,
Since nedit's find-replace dialog can use regular expressions it is
quite powerful. If you type the following in the Find field of the
(Page\s+\d+).+\n(?n.+?)Example\s*\n
\1\n
This should do the job. Of course you need to check the "Regular
Expression" checkbox before hitting the "Window" button.
One caveat. The default maximum length of a search/replace string is
possibly not enough. Recent versions of source/nedit.h have:

#define SEARCHMAX 5119

If you are happy building your own version you can increase this and
recompile. I usually change it to 32767.
--
There's no point in being grown up if you can't be childish sometimes.
-- Dr. Who
--
NEdit Discuss mailing list - Discuss-***@public.gmane.org
http://www.nedit.org/mailman/listinfo/discuss
marvin carandang
2009-07-30 01:29:12 UTC
Permalink
Hi Andrew,

Thanks for this. This is really interesting to know. I am lucky though, because in this case...the length of the characters that I want deleted is certainly less than 5000.




________________________________
From: Andrew Hood <ajhood-ci3VU6HO4IOHXe+***@public.gmane.org>
To: General NEdit discussion list <discuss-***@public.gmane.org>
Sent: Thursday, July 30, 2009 12:04:34 AM
Subject: Re: Need help please
Post by Offer Kaye
Post by marvin carandang
Hello Nedit Experts,
Since nedit's find-replace dialog can use regular expressions it is
quite powerful. If you type the following in the Find field of the
(Page\s+\d+).+\n(?n.+?)Example\s*\n
\1\n
This should do the job. Of course you need to check the "Regular
Expression" checkbox before hitting the "Window" button.
One caveat. The default maximum length of a search/replace string is
possibly not enough. Recent versions of source/nedit.h have:

#define SEARCHMAX 5119

If you are happy building your own version you can increase this and
recompile. I usually change it to 32767.
--
There's no point in being grown up if you can't be childish sometimes.
                -- Dr. Who
--
NEdit Discuss mailing list - Discuss-***@public.gmane.org
http://www.nedit.org/mailman/listinfo/discuss
--
NEdit Discuss mailing list - Discuss-***@public.gmane.org
http://www.nedit.org/mailman/listinfo/discuss
marvin carandang
2009-08-03 07:56:22 UTC
Permalink
Hi Kaye,

It did work! Thank you very much!



________________________________
From: Offer Kaye <offer.kaye-***@public.gmane.org>
To: General NEdit discussion list <discuss-***@public.gmane.org>
Sent: Wednesday, July 29, 2009 4:23:50 PM
Subject: Re: Need help please
Post by marvin carandang
Hello Nedit Experts,
Since nedit's find-replace dialog can use regular expressions it is
quite powerful. If you type the following in the Find field of the
Replace dialog:

(Page\s+\d+).+\n(?n.+?)Example\s*\n

and the following in the Replace field:

\1\n


This should do the job. Of course you need to check the "Regular
Expression" checkbox before hitting the "Window" button.

To understand the above please see NEdit's regular-expressions
documentation. In any case your question is not really an "NEdit"
question, per-se, but more of a regexp-related question. For example
the following Perl one-liner, run from the Unix command-line, does the
job in nearly the same manner - or at least it should :-)

perl -pi.bak -0 -e's/(Page\s+\d+).+?Example\s*\n/$1\n/sg' <input_file>

This will replace the input_file contents and save the original in a
backup input_file.bak.

Cheers,
--
Offer Kaye
--
NEdit Discuss mailing list - Discuss-***@public.gmane.org
http://www.nedit.org/mailman/listinfo/discuss
--
NEdit Discuss mailing list - Discuss-***@public.gmane.org
http://www.nedit.org/mailman/listinfo/discuss
Loading...