1

I am new here and hope you can help me with this one. I have an PL/SQL Procedure and i am trying to remove the comments from the script using shell script. I have used this script for the single line comments;

grep -v "^--" file_name > file_name2

but i don't know how to process the comments that contains multiple lines. Say for example;

/* This 

line 

is just

a comment*/

Thanks in advance!

Ramchandra Apte
  • 4,033
  • 2
  • 24
  • 44
  • Something here: http://stackoverflow.com/questions/13061785/remove-multi-line-comments sed -r ':a; s%(.*)/\*.*\*/%\1%; ta; /\/\*/ !b; N; ba' Your_file – user1587504 Nov 26 '13 at 13:08

1 Answers1

0

This should be a comment but I do not have enough rep points to add a comment. Anyway, be advised your grep line removes comments only if they start at the beginning of the line.

Try this instead which tells grep the pattern is a regular expression and matches from where the double-dashes occur to the end of the line (check the man page for your grep to be sure of the switch used to tell it the pattern is a regular expression):

grep -v -e "--.*$" filename

Also, be aware that comments can appear in a SQL statement, and hints if used look like a comment but most likely should not be removed. SQL with a hint example:

  SELECT /*+ ALL_ROWS */ employee_id, last_name, salary, job_id
  FROM employees
  WHERE employee_id = 7566;

Be very careful when trying to strip multi-line comments to make sure they are not really hints. Info on hints: http://docs.oracle.com/cd/E11882_01/server.112/e41573/hintsref.htm#PFGRF005

Gary_W
  • 9,933
  • 1
  • 22
  • 40