Sponsored Content
Top Forums Shell Programming and Scripting How to remove comments from a bash script? Post 302660625 by LessNux on Friday 22nd of June 2012 05:26:17 PM
Old 06-22-2012
Question

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.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Remove comments...

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)
Discussion started by: LivinFree
1 Replies

2. Shell Programming and Scripting

please explain this sed shell script to remove C++ comments.

#! /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)
Discussion started by: Priyaranjan
1 Replies

3. Shell Programming and Scripting

how can i remove comments in random positions in a file?(bash)

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)
Discussion started by: bashuser2
2 Replies

4. Shell Programming and Scripting

Sed script, changing all C-comments to C++-comments

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)
Discussion started by: black_hawk
2 Replies

5. UNIX for Dummies Questions & Answers

Remove blank lines and comments from text file

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)
Discussion started by: msb65
3 Replies

6. Shell Programming and Scripting

sed remove css comments

Is there a way that I can use sed to remove lines with css comments like this? /* comment */ (9 Replies)
Discussion started by: gravesit
9 Replies

7. Shell Programming and Scripting

sed remove comments

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)
Discussion started by: gravesit
5 Replies

8. UNIX for Dummies Questions & Answers

Remove SAS comments using UNIX

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)
Discussion started by: saaisiva
1 Replies

9. Shell Programming and Scripting

Bash script to find comments in file

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)
Discussion started by: ksmarine1980
11 Replies

10. Shell Programming and Scripting

Remove comments like pattern from text

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)
Discussion started by: VikashKumar
6 Replies
SDIFF(1)							     GNU Tools								  SDIFF(1)

NAME
sdiff - find differences between two files and merge interactively SYNOPSIS
sdiff -o outfile [options] from-file to-file DESCRIPTION
The sdiff command merges two files and interactively outputs the results to outfile. If from-file is a directory and to-file is not, sdiff compares the file in from-file whose file name is that of to-file, and vice versa. from-file and to-file may not both be directories. sdiff options begin with -, so normally from-file and to-file may not begin with -. However, -- as an argument by itself treats the remaining arguments as file names even if they begin with -. You may not use - as an input file. sdiff without -o (or --output) produces a side-by-side difference. This usage is obsolete; use diff --side-by-side instead. Options Below is a summary of all of the options that GNU sdiff accepts. Each option has two equivalent names, one of which is a single letter preceded by -, and the other of which is a long name preceded by --. Multiple single letter options (unless they take an argument) can be combined into a single command line argument. Long named options can be abbreviated to any unique prefix of their name. -a Treat all files as text and compare them line-by-line, even if they do not appear to be text. -b Ignore changes in amount of white space. -B Ignore changes that just insert or delete blank lines. -d Change the algorithm to perhaps find a smaller set of changes. This makes sdiff slower (sometimes much slower). -H Use heuristics to speed handling of large files that have numerous scattered small changes. --expand-tabs Expand tabs to spaces in the output, to preserve the alignment of tabs in the input files. -i Ignore changes in case; consider upper- and lower-case to be the same. -I regexp Ignore changes that just insert or delete lines that match regexp. --ignore-all-space Ignore white space when comparing lines. --ignore-blank-lines Ignore changes that just insert or delete blank lines. --ignore-case Ignore changes in case; consider upper- and lower-case to be the same. --ignore-matching-lines=regexp Ignore changes that just insert or delete lines that match regexp. --ignore-space-change Ignore changes in amount of white space. -l --left-column Print only the left column of two common lines. --minimal Change the algorithm to perhaps find a smaller set of changes. This makes sdiff slower (sometimes much slower). -o file --output=file Put merged output into file. This option is required for merging. -s --suppress-common-lines Do not print common lines. --speed-large-files Use heuristics to speed handling of large files that have numerous scattered small changes. -t Expand tabs to spaces in the output, to preserve the alignment of tabs in the input files. --text Treat all files as text and compare them line-by-line, even if they do not appear to be text. -v --version Output the version number of sdiff. -w columns --width=columns Use an output width of columns. Note that for historical reasons, this option is -W in diff, -w in sdiff. -W Ignore horizontal white space when comparing lines. Note that for historical reasons, this option is -w in diff, -W in sdiff. SEE ALSO
cmp(1), comm(1), diff(1), diff3(1). DIAGNOSTICS
An exit status of 0 means no differences were found, 1 means some differences were found, and 2 means trouble. GNU Tools 22sep1993 SDIFF(1)
All times are GMT -4. The time now is 02:57 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy