Find the answer to your Linux question:
Results 1 to 2 of 2
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 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jan 2010
    Posts
    4

    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
    Location
    Munich
    Posts
    3,392
    Something like this should do it:
    Code:
    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.

    Note:
    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:
    Code:
     *
    is not a comment in php, it is rather (for a comment block)
    Code:
    /*
    .
    .
    */
    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
  •