Sponsored Content
Top Forums Shell Programming and Scripting How to remove comments from a bash script? Post 302660309 by methyl on Friday 22nd of June 2012 10:30:35 AM
Old 06-22-2012
@arrals_vl
It's the Perl program at the beginning of Post #1 .
 

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
unifdef(1)						      General Commands Manual							unifdef(1)

NAME
unifdef - Removes #ifdefed lines SYNOPSIS
unifdef [-tlc] [-Dsymbol] [-idsymbol] [-iusymbol] [file] [-Usymbol] The unifdef command partially simulates the behavior of the C preprocessor in processing #ifdef conditionals. OPTIONS
Complements the action of unifdef; retains lines that would normally be removed and removes lines that would normally be retained. Speci- fies symbol as a defined #ifdef symbol. Specifies defined lines inside certain #ifdefs to be ignored but copied out. Specifies undefined lines inside certain #ifdefs to be ignored and not copied out. Replaces removed lines with blank lines instead of deleting them. Pro- cesses plain text (rather than C code) input. The unifdef command does not try to recognize comments, single quotes, and double quotes. Specifies symbol as an undefined #ifdef symbol. DESCRIPTION
The unifdef command recognizes nested #ifdefs, comments, single and double quotes of C syntax so that it can function correctly, but does not include files or interpret macros. The unifdef command recognizes, but does not remove comments. The unifdef command takes its input from stdin if no file argument is given, and copies its output to stdout. You specify the symbols you want defined with -Dsymbol or undefined with -Usymbol and the lines inside those #ifdefs are copied to the out- put or removed, as appropriate. The #ifdef, #ifndef, #else, #elif, and endif lines associated with symbol are also removed. The #ifdefs involving unspecified symbols are untouched and copied out along with their associated #ifdef, #else, elif, and #endif lines. If the same symbol appears in more than one argument, only the first occurrence is significant. For instance, if an #ifdef X occurs nested inside another #ifdef X, the inside #ifdef is considered an unrecognized symbol. If you use #ifdefs to delimit non-C lines, such as comments or unfinished code, it is necessary to specify which symbols are to be used for that purpose. Otherwise, the unifdef command tries to parse for quotes and comments in those #ifdef lines. Keywords The following keywords can be used with the unifdef command: ifdef ifndef else endif elif The unifdef command uses the elif keyword as follows. (Note that "Understood" means unifdef knows how to convert elif to if.) Understood Not understood Not understood For example: # ifdef X x # elif defined (Y) y # elif defined (A) || defined (B) a # else default # endif The following list shows the results of using the elif keyword with variables: -DX x -UX # if defined (Y) y # elif defined (A) || defined (B) a # else default # endif -UX -DY y -UY -UX # if defined (Y) y # elif defined (A) || defined (B) a # else default # endif -UY -UX -DA # if defined (Y) y # elif defined (A) || defined (B) a # else default # endif NOTES
The unifdef command cannot process cpp constructs such as: #if defined(X) || defined(Y) DIAGNOSTICS
The unifdef command can fail for several reasons: a premature end of file, or an inappropriate else, elif, or endif. EXIT STATUS
Exit status is 0 if output is an exact copy of input, 1 if not, 2 if the unifdef command fails. EXAMPLES
The following command line causes the unifdef command to read the file original.c and remove the #ifdef A lines. It then removes every- thing following an #elif/#else associated with the #ifdef A down to the #endif: unifdef -DA original.c > modified.c The following command line causes the unifdef command to read the file original.c, and remove the #ifdef A down to either its associated #elif/#else, or its associated #endif: unifdef -UA original.c > modified.c In the case of the #elif, the #elif is replaced with #if. In the case of #else, the #else is deleted along with its associated #endif. SEE ALSO
Commands: diff(1) unifdef(1)
All times are GMT -4. The time now is 08:38 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy