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

    help with search and replace

    hi guys...

    i have multiple php files with some comments. i want to remove the comment automatically using grep or find or some other built in linux command. the comment is like this

    * this is an example of a line

    how can i use the command line to automatically find the above line with starts with * and remove the entire line automatically? i know what the exact line to remove is, so please help me with the command i need to type. please take note that the starting character starts with a blank space and then the aterick character followed by the line to be removed

    please help me guys... im lost

  2. #2
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Something like this should do it:
    find <PHP_DIRECTORY> -type f -iname "*\.php" -exec sed  '/^\([[:blank:]]\)\* this is an example of the line/d' {} \;
    This will *not yet* change any files, but just output a concatination of all php files with the mentioned line removed.
    After you verified the correct output, you can add the -i flag to sed for in-place editing.

    The sed will look for exactly *one* space/tab, followed by "* this is an example of the line".
    But it easy to adjust to e.g. multipe spaces or none at all or optional.

    That said:
    is not a comment in php, it is rather (for a comment block)
    But maybe the "body" of your comments have space + asteriks
    Last edited by Irithori; 09-06-2011 at 01:14 PM.
    You must always face the curtain with a bow.

Posting Permissions

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