Re: [Tutor] deleting one line in multiple files

2007-09-14 Thread Alan Gauld
"bhaaluu" <[EMAIL PROTECTED]> wrote > I'm also looking into 'sed' for doing this. I've used 'sed' in the > past for > deleting a specific line from files, as well as doing simple search > and > replace in a file. I just figured that if it can be done in 'sed,' > it > can be done in Python muc

Re: [Tutor] deleting one line in multiple files

2007-09-14 Thread bhaaluu
Greetings, Okay, I've had a chance to experiment with both solutions, and both of them work as advertised. For those just tuning in, what I wanted to do was delete a line in each file in a directory that had a specific pattern in the line. There were over two hundred files in the directory, and I

Re: [Tutor] deleting one line in multiple files

2007-09-14 Thread Michael Langford
Sed is a little easier than python for this project, but python is more flexible. Sed would be sed -e "s/^.*\

Re: [Tutor] deleting one line in multiple files

2007-09-14 Thread bhaaluu
Greetings, Many thanks to wormwood_3 and Kent for their help. Summary: The working script looks like this: # the lines with '

Re: [Tutor] deleting one line in multiple files

2007-09-14 Thread Kent Johnson
bhaaluu wrote: > On 9/13/07, wormwood_3 <[EMAIL PROTECTED]> wrote: > >> I think the problem is that the original script you borrowed looks >> at the file passed to input, and iterates over the lines in that file, removing them if they match your pattern. What you actually want to be doing is itera

Re: [Tutor] deleting one line in multiple files

2007-09-14 Thread bhaaluu
On 9/13/07, wormwood_3 <[EMAIL PROTECTED]> wrote: > I think the problem is that the original script you borrowed looks at the > file passed to input, and iterates over the lines in that file, removing them > if they match your pattern. What you actually want to be doing is iterating > over the

Re: [Tutor] deleting one line in multiple files

2007-09-13 Thread wormwood_3
Thought I would do some more testing and get you a more finalized form this time. So I took the mygrep.py script, and put it in a folder with 3 test files with content like this: I am some lines of text yep I love text 435345 345345345 Then I ran: [EMAIL PROTECTED]:~/test$ python mygrep.py "

[Tutor] deleting one line in multiple files

2007-09-13 Thread wormwood_3
I think the problem is that the original script you borrowed looks at the file passed to input, and iterates over the lines in that file, removing them if they match your pattern. What you actually want to be doing is iterating over the lines of your list file, and for each line (which represent

[Tutor] deleting one line in multiple files

2007-09-13 Thread bhaaluu
Greetings, I'm running Python 2.4.3 on a GNU/Linux box. This question is about using 'fileinput.' I have a directory of files, and I've created a file list of the files I want to work on: $ ls > file.list Each file in file.list needs to have a line removed, leaving the rest of the file intact.