I find it sufficient to strip lines which consist totally of comments or white space when examining a script. This is only for visual inspection because it can still remove significant lines from Here Documents.
Stripping comments on a permanent basis is not advisible at all and could breach copyright in commercial code.
My main purpose for the post #1 is to compare two copies (or two versions) of the script, ignoring comments and meaningless white spaces that do not affect execution.
If commands like diff or cmp provide an option to ignore comments and meaningless white spaces, and if two copies (or two versions) of the script can be compared without permanently removing comments and meaningless white spaces, I would be partially satisfied. Does anyone know how to compare two copies (or two versions) of bash script, ignoring comments and meaningless white spaces? I would appreciate it if you show me such a technique.
Even if diff or cmp has an option to ignore comments and meaningless white spaces, the permanent removal of comments and meaningless white spaces would be useful in the following situation. If they are permanently removed, I would be able to take the resultant copies to a GUI OS. I feel more comfortable to perform the comparison on a graphical environment on a GUI OS, after performing the removal on a text-based Unix machine.
My main purpose for the post #1 is to compare two copies (or two versions) of the script, ignoring comments and meaningless white spaces that do not affect execution.
Again, a program that can tell the difference between comments and meaningful code in a shell script, is probably a shell...
I recently got to know that, if a hash mark (#) to begin a shell comment is not placed at the beginning of a line, then the hash mark must be preceded by a horizontal whitespace. (The # mark is also called a "pound sign" in the United States, and a "number sign" as a Unicode name.)
I have never seen any Unix guide documents explicitly state the need for a space before a hash mark (#) to begin a comment. C++ allows comment-leading double slashes (//) to immediately follow another token without any spaces preceding the double slashes. So, I thought that BASH would not require any spaces before a hash mark (#) that begins a comment.
I recently read carefully a man page of bash, which writes, "a word beginning with # causes that word and all remaining characters on that line to be ignored." The phrase "a word beginning with #" obscurely implies that a space is required before # if the comment-leading # is not placed at the beginning of a line.
Now, let me go back to my initial problem. I need to compare two copies of a bash script. One copy is full of detailed comments. The other copy has few or no comments. The two copies differ also in spacing. In terms of command statements that affect execution, the two copies are almost identical. So, I would like to remove comments before comparing the two copies. The following script now gives me most of what I wanted. I named the script "rmcomment.sh".
Hi , We need to remove comment like pattern from a code text. The possible comment expressions are as follows.
Input
BizComment : Special/*@
Name:bzt_53_3aea640a_51783afa_5d64_0
BizHidden:true
@*/
/* lookup Disease
Category Therapuetic Class */
a=b;... (6 Replies)
As I stated in a previous thread - I'm a newbie to Unix/Linux and programming. I'm trying to learn the basics on my own using a couple books and the exercises provided inside.
I've reached an exercise that has me stumped. I need to write a bash script that will will read in a file and print the... (11 Replies)
I have tried a lot, Need your help guys.
SAS Program:
data one ; /* Data step */
Input name $; /*Dec variables*/
I want to remove the commented part(/* Data step */) alone. I have tried using sed command but it is deleting the entire line itself. i need unix command to separate this and... (1 Reply)
I need to use sed to remove comments from files. I am using this, but it only works on comments that start at the beginning of the line.
sed /^"\/\/"/d
In most of the files I have comments like this:
code // Comments
or
tab // Comments (5 Replies)
Hi,
I am using BASH. How can I remove any lines in a text file that are either blank or begin with a # (ie. comments)? Thanks in advance.
Mike (3 Replies)
I must write a script to change all C++ like comments:
// this is a comment
to this one
/* this is a comment */
How to do it by sed? With file:
#include <cstdio>
using namespace std; //one
// two
int main() {
printf("Example"); // three
}//four
the result should be: (2 Replies)
Suppose i have a file like this:
#bla bla
#bla bla bla bla bla
Bla
BLA
BLA BLA #bla bla
....
....
how can i remove all comments from every line,even if they are behind commands or strngs that are not comments?
any idea how i could do that using awk? (2 Replies)
#! /bin/sed -nf
# Remove C and C++ comments, by Brian Hiles (brian_hiles@rocketmail.com)
# Sped up (and bugfixed to some extent) by Paolo Bonzini (bonzini@gnu.org)
# Works its way through the line, copying to hold space the text up to the
# first special character (/, ", '). The original... (1 Reply)
It may be a no-brainer, but the answer is escaping me right now:
I'm trying to write a little script to remove all comments from .c source... I was thinking sed, but I'm not a very strong regexp user (e.g. I suck with sed).
I tried dumping the file into:
sed -e 's/\/\* * \*\///g'
and several... (1 Reply)