Results 1 to 2 of 2

Thread: Remove comment script

  1. #1
    Junior Member
    Join Date
    May 2013
    Thanked 0 Times in 0 Posts
    Rep Power

    Question Remove comment script

    Hello All,

    I'm trying to write a shell script that removes the input (another program) comment and outputs the code only. I came with the command line solution, but I don't know how to put it into a bash program.

    Here is the command line solution:

    sed -e '1{/^#!/ {p}}; /^[\t\ ]*#/d;/\.*#.*/ {/[\x22\x27].*#.*[\x22\x27]/ !{:regular_loop s/\(.*\)*[^\]#.*/\1/;t regular_loop}; /[\x22\x27].*#.*[\x22\x27]/ {:special_loop s/\([\x22\x27].*#.*[^\x22\x27]\)#.*/\1/;t special_loop}; /\\#/ {:second_special_loop s/\(.*\\#.*[^\]\)#.*/\1/;t second_special_loop}}' "name of your program"

    Please help.

  2. #2
    Senior Member cfajohnson's Avatar
    Join Date
    May 2009
    Thanked 44 Times in 36 Posts
    Rep Power


    (Only superficially tested.)
    sed -e '/^\#/d' -e 's/[[:blank:]]\#.*//' "$file"
    Chris F.A. Johnson <>
    Shell programmer and author

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. How to comment a line in a text file
    By vijaytrendz in forum Shell scripting
    Replies: 9
    Last Post: 22nd April 2013, 01:08 AM
  2. SED Script to remove a few lines out of a file
    By cjredding in forum Shell scripting
    Replies: 33
    Last Post: 6th September 2010, 12:06 PM
  3. [Solved] Comment out lines in .htaccess using sed command
    By cosminnci in forum Shell scripting
    Replies: 2
    Last Post: 4th July 2009, 01:16 AM
  4. BIND named.conf search zone and comment it out script
    By asim.mcp in forum Shell scripting
    Replies: 2
    Last Post: 15th June 2009, 12:39 PM
  5. Script to remove executable files
    By sweta in forum Shell scripting
    Replies: 4
    Last Post: 12th March 2005, 01:21 PM

Tags for this Thread

Posting Permissions

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