Find the answer to your Linux question:
Results 1 to 3 of 3
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    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.

  2. #2
    Linux Enthusiast
    Join Date
    Apr 2004
    Google is your friend.

    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,

    To be good, you must first be bad. "Newbie" is a rank, not a slight.

  3. #3
    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:

    find /path/to/files -maxdepth 1 -type f -name "*.php" -exec sed -i '/pattern/ d' {} \;
    '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.

  4. $spacer_open

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts