Remove Comment Lines From Script/Input File


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Remove Comment Lines From Script/Input File
# 1  
Remove Comment Lines From Script/Input File

Hello,

I have a SAS code that predominantly has comments line and the real code like below and i want to remove ONLY THE COMMENTS from the code in the single line or spanned across multiple lines.

Code:
/********************************************************************
*** This Is a Comment Spanned Across Multiple Lines  ***
*********************************************************************/
data output;
  set input;
run;

* This Is a Comment But Only On a Single Line, Which Starts With Single or Multiple Asterisk and Ends With SemiColon;

data output2;
    set input2; /* This Is Another Comment In a Line which has Valid code and I do not want to remove this actual code but just want to remove this comment alone */
run;

Please let me know any options to achieve this.

I expect my output to be like below (without any of the above format of comment lines).

Code:
data output;
  set input;
run;

data output2;
    set input2; 
run;

Thanks,
Arun.

Last edited by arooonatr; 3 Weeks Ago at 02:09 PM..
# 2  
Why would anybody would want to remove comments in source code? Usually the person who wrote the code leave comments for the understanding of the code...
Do you believe it will run faster after?
If so you have a very little of how SAS works...
Ive seen people having to rewrite code because not understanding how it worked...


(P.S. I have more than 20 years of SAS installation, administration, I started with SAS6 on HP-UX, now running 9.4...on AIX)
# 3  
Hello VBE,

That's not my intention and I am never going to overwrite the program. I am scanning a program and want to remove the comments while processing so that the keywords my scanning programs looks for will avoid looking through the comment lines.

Thanks for your response!
# 4  
It is quite simple: you need a (recursive) parser for this, the same way the language is interpreted (i suppose?) by one. I suggest to retrieve your yacc utility and start writing...


If you are looking for a regex-solution (grep, sed, awk, ...): none of these will work correctly, because languages are context-sensitive. Consider i.e. :


Code:
program_text /* this is a comment */ more program_text

and:

Code:
program_text "/* this is not a comment any more */" more program_text

and that is just one of the myriads of possibilities to lead a regexp astray.
This User Gave Thanks to foad For This Post:
# 5  
It is indeed difficult to give a complete answer for all corner cases, however, for simple cases, you could try how far something like:
Code:
perl -p0777e 's#/\*.*?\*/|\*.*?\;##sg' file

would get you. This could possibly work for one-off cases, but it will not be fool proof and can not be relied upon...

Last edited by Scrutinizer; 3 Weeks Ago at 05:13 PM..
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #613
Difficulty: Medium
Examples of complex numbers in Python are (-5+4j) and (2.3 - 4.6j).
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script using awk to find and replace a line, how to ignore comment lines

Hello, I have some code that works more or less. This is called by a make file to adjust some hard-coded definitions in the src code. The script generated some values by looking at some of the src files and then writes those values to specific locations in other files. The awk code is used to... (3 Replies)
Discussion started by: LMHmedchem
3 Replies

2. Shell Programming and Scripting

Script to remove lines within file

AIX. we have multiple files eg B1234567 B1235468 etc. (numbers change daily, only constant is the B prefix) trying to use using sed '/numberrange and length varies /d ' to remove a specific number range out of one of these files , we just don't know which one its in, as it could be in... (4 Replies)
Discussion started by: newbee2015
4 Replies

3. Shell Programming and Scripting

Please help, need to create script to remove lines by date in file

Please Help (novice to PERL and SHELL scripting)…. Need to create a script which removes all lines in $filename = "cycle_calendar_ftp_out" older than current date – a variable which will be a number of days passed to script. For Ex it will look at the end date which is the last field (4) and... (2 Replies)
Discussion started by: m3pwr
2 Replies

4. Shell Programming and Scripting

Comment ( -- ) lines from 10 to 25 for every .sql file

Platform : RHEL 5.4 I have several .sql files in a directory. I want to comment lines 10 to 25 for all .sql files. How can I do this ? The symbol for comment in SQL is -- eg: -- select salary from emp where empname = 'URS' ; (3 Replies)
Discussion started by: omega3
3 Replies

5. UNIX for Dummies Questions & Answers

Comment lines in file without vi editor

Legends, Can you please help me in following. I need to comment lines from /tmp/a.txt from the line A to line B through the command prompt only. Please use variables not direct values like 2 or 5 It can be done with VI editor but its not matches with my requirement (: 2,5 s/^/#/g). ... (1 Reply)
Discussion started by: sdosanjh
1 Replies

6. Shell Programming and Scripting

add line and remove comment in some script

Hi, i need some help. i am not sure about my idea. I have a script directory under my home directory,which has a lot of scripts in it. These are some names of the scripts in /axxhome/prdv/script aly300.sh axt300.sh arv300.sh clp300.sh ctth300.sh aly400.sh axt400.sh arv400.sh... (6 Replies)
Discussion started by: debu000
6 Replies

7. Shell Programming and Scripting

using awk to comment out lines to the end of file

Hello, I have a file as follow a b c c d d e I would like to write a awk command to insert # from the first occurence of "c" to the end of the files. OUTPUT should be like this a b #c (5 Replies)
Discussion started by: phamp008
5 Replies

8. Shell Programming and Scripting

Remove the comment symbol ' from a file.

I want to remove the commented lines in a file identified by ' symbol at the start of each ine. A sample example will be like: Input ----- 'IFerr_flag=0THEN iferr_flag=0then iferr_flag=0then iferr_flag=0then iferr_flag=0then iferr_flag=0then iferr_flag=0then Output -------... (3 Replies)
Discussion started by: joyan321
3 Replies

9. Shell Programming and Scripting

Shell script to remove duplicates lines in a file

Hi, I am writing a shell script that needs to remove duplicate lines within a file by category. example: section a a c b a section b a b a c I need to remove the duplicates within th category with out removing the duplicates from the 2 different sections (one of the a's in section... (1 Reply)
Discussion started by: RichElks
1 Replies

10. Shell Programming and Scripting

a remove script taken in input a file which contain a list of directories

Hi, I'm looking to delete some files from directories. I've just put in a file the location of these files. e.g: in file supprs.txt there is: /usr/host/t1.txt /etc/dev/u1.java /home/new/files/view.c Is it possible to take this file "supprs.txt" as a parameter in a shell command ? (2 Replies)
Discussion started by: yeclota
2 Replies

Featured Tech Videos