Results 1 to 3 of 3
I was wondering if there was a way to search file content and remove the line that was found.
I have thousands of php scripts that need lines removed and ...
- 10-26-2008 #1Just Joined!
- Join Date
- Oct 2008
- Posts
- 4
search file content and remove that line?
I was wondering if there was a way to search file content and remove the line that was found.
I have thousands of php scripts that need lines removed and i don't want to do this one by one.
- 10-26-2008 #2Linux Enthusiast
- Join Date
- Apr 2004
- Location
- UK
- Posts
- 658
Google is your friend.
http://www.linuxforums.org/forum/lin...tml#post577367
You should be able to do something suitable with that, although remember not to redirect the output directly back into your php file or it will get clobbered.
Let us know how you get on,
Chris...To be good, you must first be bad. "Newbie" is a rank, not a slight.
- 10-26-2008 #3Linux User
- Join Date
- Jun 2007
- Posts
- 318
If you have thousands of files to edit I would use the sed command with the -i option (edit files in place) within the find command. Something like this:
'pattern' is the line to delete. If you specify the entire line then prepend and append it with '^' (start of line) and '$' (end of line) to make sure sed deletes only that line. Make sure to copy/backup the files before you run the command just in case something goes wrong.Code:find /path/to/files -maxdepth 1 -type f -name "*.php" -exec sed -i '/pattern/ d' {} \;


Reply With Quote
