Re: [OFF] sed equivalent of something easy in python

2010-10-30 Thread Mark Wooding
Jussi Piitulainen writes: > Daniel Fetchinson writes: > > > The pattern is that the first line is deleted, then 2 lines are > > kept, 3 lines are deleted, 2 lines are kept, 3 lines are deleted, > > etc, etc. > > So, is there some simple expression in Python for this? (item for i, item in enumera

Re: [OFF] sed equivalent of something easy in python

2010-10-27 Thread Arnaud Delobelle
Tim Chase writes: > On 10/27/10 09:39, Jussi Piitulainen wrote: >>> So, is there some simple expression in Python for this? Just asking >>> out of curiosity when nothing comes to mind, not implying that there >>> should be or that Python should be changed in any way. >> >> To expand, below is the

Re: [OFF] sed equivalent of something easy in python

2010-10-27 Thread Tim Chase
On 10/27/10 09:39, Jussi Piitulainen wrote: So, is there some simple expression in Python for this? Just asking out of curiosity when nothing comes to mind, not implying that there should be or that Python should be changed in any way. To expand, below is the best I can think of in Python 3 and

Re: [OFF] sed equivalent of something easy in python

2010-10-27 Thread Jussi Piitulainen
Jussi Piitulainen writes: > Daniel Fetchinson writes: > > > This question is really about sed not python, hence it's totally > > off. But since lots of unix heads are frequenting this list I > > thought I'd try my luck nevertheless. > ... > > using python. The pattern is that the first line is de

Re: sed equivalent of something easy in python

2010-10-27 Thread Tim Chase
On 10/27/10 08:27, Martin Gregorie wrote: (2) made me take care of 2 files instead of 1 from now on. Not necessarily: $ cat heredoc.sh #!/usr/bin/env bash python<< 'EOF' print "hello world" def foo(): print "foo()" foo() EOF $ Or even better: $ cat hello #!/usr/bin/python print "hello

Re: [OFF] sed equivalent of something easy in python

2010-10-27 Thread Jussi Piitulainen
Daniel Fetchinson writes: > This question is really about sed not python, hence it's totally > off. But since lots of unix heads are frequenting this list I > thought I'd try my luck nevertheless. ... > using python. The pattern is that the first line is deleted, then 2 > lines are kept, 3 lines

Re: sed equivalent of something easy in python

2010-10-27 Thread Martin Gregorie
On Wed, 27 Oct 2010 03:28:16 -0700, Lie wrote: > On Oct 26, 4:04 am, Daniel Fetchinson wrote: > >> (2) made me take care of 2 files instead of 1 from now on. > > Not necessarily: > > $ cat heredoc.sh > #!/usr/bin/env bash > python << 'EOF' > print "hello world" > def foo(): > print "foo()"

Re: sed equivalent of something easy in python

2010-10-27 Thread Lie
On Oct 26, 4:04 am, Daniel Fetchinson wrote: > (2) made me take care of 2 files instead of 1 from now on. Not necessarily: $ cat heredoc.sh #!/usr/bin/env bash python << 'EOF' print "hello world" def foo(): print "foo()" foo() EOF $ $ ./heredoc.sh hello world foo() -- http://mail.python.or

Re: [OFF] sed equivalent of something easy in python

2010-10-25 Thread Daniel Fetchinson
>> using python. The pattern is that the first line is deleted, >> then 2 lines are kept, 3 lines are deleted, 2 lines are kept, >> 3 lines are deleted, etc, etc. > > If you have GNU sed, you can use > >sed -n '2~5{N;p}' > > which makes use of the GNU "~" extension. If you need a more > portabl

Re: [OFF] sed equivalent of something easy in python

2010-10-25 Thread Tim Chase
On 10/25/2010 11:25 AM, Daniel Fetchinson wrote: using python. The pattern is that the first line is deleted, then 2 lines are kept, 3 lines are deleted, 2 lines are kept, 3 lines are deleted, etc, etc. If you have GNU sed, you can use sed -n '2~5{N;p}' which makes use of the GNU "~" extens

[OFF] sed equivalent of something easy in python

2010-10-25 Thread Daniel Fetchinson
This question is really about sed not python, hence it's totally off. But since lots of unix heads are frequenting this list I thought I'd try my luck nevertheless. If I have a file with content 1 2 3 4 5 6 7 8 ... i.e. each line contains simply its line number, then it's quite easy to conve