Re: To remove some lines from a file

2006-11-04 Thread John Savage
Sebastian Busch <[EMAIL PROTECTED]> writes: >The task is: > >"Remove the first two lines that don't begin with "@" from a file." > >How would you do it with sed? Why a sed solution in a python group? sed '/^@/!{G;/\n\n\n/{P;d;};s/[^\n]*//;h;d;}' data -- John Savage (my news add

Re: To remove some lines from a file

2006-10-26 Thread Roberto Bonvallet
Sebastian Busch wrote: > The task is: > > "Remove the first two lines that don't begin with "@" from a file." awk 'BEGIN {c = 0} c < 2 && !/^@/ {c += 1; next} {print}' < mybeautifulfile -- Roberto Bonvallet -- http://mail.python.org/mailman/listinfo/python-list

Re: To remove some lines from a file

2006-10-26 Thread Sebastian Busch
Chetan wrote: > Sebastian Busch <[EMAIL PROTECTED]> writes: > >> Steve Holden wrote: >>> Sebastian Busch wrote: [EMAIL PROTECTED] wrote: > ... I would like to remove two lines from a file. ... ... grep -v ... >>> ... show ... >> grep -v "`grep -v "commentsymbol" yourfile | head -2`"

Re: To remove some lines from a file

2006-10-26 Thread Chetan
Sebastian Busch <[EMAIL PROTECTED]> writes: > Steve Holden wrote: >> Sebastian Busch wrote: >>> [EMAIL PROTECTED] wrote: ... I would like to remove two lines from a file. ... >>> ... grep -v ... >> ... show ... > > grep -v "`grep -v "commentsymbol" yourfile | head -2`" yourfile > > > i frankl

Re: To remove some lines from a file

2006-10-25 Thread Sebastian Busch
Steve Holden wrote: > Sebastian Busch wrote: >> [EMAIL PROTECTED] wrote: >>> ... I would like to remove two lines from a file. ... >> ... grep -v ... > ... show ... grep -v "`grep -v "commentsymbol" yourfile | head -2`" yourfile i frankly admit that there is also 'head' invoved ;) i really have

Re: To remove some lines from a file

2006-10-25 Thread Steve Holden
Sebastian Busch wrote: > [EMAIL PROTECTED] wrote: > >>... I would like to remove two lines from a file. >>... > > > I am quite new myself -- but wouldn't grep -v do that easier (and > perhaps faster)? > Kindly show how to use grep to solve this problem: Remove the first two lines that don't

Re: To remove some lines from a file

2006-10-25 Thread Sebastian Busch
[EMAIL PROTECTED] wrote: > ... I would like to remove two lines from a file. > ... I am quite new myself -- but wouldn't grep -v do that easier (and perhaps faster)? Greetings, Sebastian. -- http://mail.python.org/mailman/listinfo/python-list

Re: To remove some lines from a file

2006-10-25 Thread Bruno Desthuilliers
[EMAIL PROTECTED] wrote: > Dear all, > > I am quite new to python. I would like to remove two lines from a file. The canonical way to do so (at least for text files - which is the case here) is : open the source file in read mode open a tmp file in write mode for each line in source file: if

Re: To remove some lines from a file

2006-10-25 Thread umut . tabak
Thanks, I have learnt sth from the library BTW. Regards On Oct 25, 3:32 pm, "Jerry" <[EMAIL PROTECTED]> wrote: > Very inelegant, but you get the idea: > > counter = 0 > > f = open("test.txt") > for line in f.readlines(): > if line[0] != "$" and counter < 2: > counter += 1 > co

Re: To remove some lines from a file

2006-10-25 Thread Jerry
Very inelegant, but you get the idea: counter = 0 f = open("test.txt") for line in f.readlines(): if line[0] != "$" and counter < 2: counter += 1 continue else: print line, -- Jerry -- http://mail.python.org/mailman/listinfo/python-list

To remove some lines from a file

2006-10-25 Thread umut . tabak
Dear all, I am quite new to python. I would like to remove two lines from a file. The file starts with some comments, the comment sign is $. The file structure is $ $ $ $ $ $ $ . . . . $ line1 line 2 $ $ . . . $ actual commands I would like to delete those two lines at the very beginning of the