Sponsored Content
Top Forums UNIX for Advanced & Expert Users grep source code and exclude comments Post 302387467 by Loic Domaigne on Saturday 16th of January 2010 03:52:02 AM
Old 01-16-2010
What about letting the preprocessor to do the work? Using gcc:
Quote:
cpp -fpreprocessed foo.c | grep type
HTH,
Loïc.
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

grep - to exclude lines beginning with pattern

11132 13069 11137 11142 13070 Can I use grep command to exclude all lines beginning with 13? I dont want to use grep -v 13 as potentially there will be a number with something like 11013 that I would exclude in error.. (2 Replies)
Discussion started by: frustrated1
2 Replies

2. UNIX for Advanced & Expert Users

how to exclude the GREP command from GREP

I am doing "ps -f" to see my process. but I get lines that one of it represents the ps command itself. I want to grep it out using -v flag, but than I get another process that belongs to the GREP itself : I would like to exclude # ps -f UID PID PPID C STIME TTY TIME CMD... (2 Replies)
Discussion started by: yamsin789
2 Replies

3. UNIX for Dummies Questions & Answers

grep exclude/find single and double quotes

Hello, I'm trying to use grep or egrep to exclude a whole range of characters but how do I exclude both a single and a double quote. It might be easier to say how do I use grep to find both single and double quotes. grep ' ' " ' file grep detects the first single quote within my... (4 Replies)
Discussion started by: Lindy_so
4 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. Shell Programming and Scripting

Using Grep Include/Exclude Files

I wrote this korn script and ran into a hole. I can use find to exclude all the hidden directories and to use my include file/exclude files for running a full backup find / -depth -ipath '/home/testuser/.*' -prune -o -print| grep -f include.mydirs | grep -v -f exclude.mydirs but when I... (8 Replies)
Discussion started by: metallica1973
8 Replies

6. Shell Programming and Scripting

Grep for a srting & exclude two folders

Hi, Below is the command to grep for a string under grep -r "redeem" /home/tom Need to make it case insensitive and exclude logs & tmp folders under /home/tom directory in my Search. Need this in Linux. (1 Reply)
Discussion started by: mohtashims
1 Replies

7. Shell Programming and Scripting

Exclude dash in grep

Hi, I must be overlooking something, but I don't understand why this doesn't work. I'm trying to grep on a date, excluding all the lines starting with a dash: testfile: #2013-12-31 2013-12-31code: grep '^2013-12-31' testfileI'm expecting to see just the second line '2013-12-31' but I don't... (3 Replies)
Discussion started by: Subbeh
3 Replies

8. Shell Programming and Scripting

Grep last two lines, calc & adding comments

....... 06/09/2013|12:00:00 PM|3|26112|40|44032|27419.7|6 1 0 93 |6|1|0|93 06/09/2013|12:30:00 PM|3|26112|40|44032|27491|11 4 0 85 |11|4|0|85 I have "sysperf.out" file containing the lines above. What I like to have on the output is: Node: prod1db ===> this is the hostname Date:... (7 Replies)
Discussion started by: Daniel Gate
7 Replies

9. Shell Programming and Scripting

Exclude multiple lines using grep

Hi, I'm working on a shell script that reports service status on a database server. There are some services that are in disabled status that the script should ignore and only check the services that are in Enabled status. I output the service configuration to a file and use that information to... (5 Replies)
Discussion started by: senthil3d
5 Replies
cpp(1)							      General Commands Manual							    cpp(1)

NAME
cpp - the C language preprocessor SYNOPSIS
/usr/lib/cpp [option...] [ifile[ofile]] OPTIONS
The cpp command recognizes the following options: Preprocess the input without producing the line control information used by the next pass of the C compiler. By default, cpp strips C-style comments. If the -C option is specified, all comments (except those found on cpp direc- tive lines) are passed along. Tell cpp not to issue warning messages. Set the limit of nesting levels for include files. The default is 50. Sets a limit on the number of errors that the compiler will flag. The default is 30. Treat comments in the old way; delete them and replace them with nothing. This is the default in -std0 mode. The default in -std or -std0 mode is to replace comments with a space. Cause cpp to expand __FILE__ to 'filename' instead of to "filename" (the default). Remove any definition of name that was previously defined with the -D option. The -U option is ignored if it is specified without a name. Define name as if by a #define directive. If the def argument is not specified, name is defined as 1. If name is not specified, the -D option is ignored. The -D option has lower precedence than the -U option. That is, if the same name is used in both a -U option and a -D option, the name will be undefined regardless of the order of the options. Specify a search path for include files whose names do not indicate a specific directory path (that is, include files whose names do not begin with a /). The actual search path depends upon the form of the #include directive used for the file: If the #include" filename" form of the directive is used, the C macro preprocessor searches for the file at the following locations: first in the directory in which it found the file that contains the directive, then in the search path indicated by the -I option, and finally in the standard directory, /usr/include. If the include <filename> form of the directive is used, the preprocessor searches for the file first in the search path indicated by the -I option, and then in the standard directory, /usr/include. You can specify multiple iterations of the -I[dir] option in the cc command line. If no dir is specified in any iteration of the -I[dir] option, the C macro preprocessor never searches the standard directory, /usr/include, for #include files. The -nocurrent_include option can also modify the search path. Change the behavior of the #include "filename" directive to not search the source file's directory for filename. This option causes the #include "filename" directives to behave like #include <filename> directives. This option allows makefiles to control the search order for header files by using -I options. Print, one per line on standard output, the path names of included files. Each is prefixed with the last component name of ifile and the suf- fix is changed to followed by a colon (:) and a space (for example, hello.o: /usr/include/stdio.h). The cpp command indents lines, as appropriate, to indicate where an included file itself includes another included file. Produce a dependency file, which has the suffix appended to the object file name. This dependency file is created even if the object file is not. The information and the format in the dependency file is identical to that produced by the -M option. This option allows dependency information to be gener- ated at the same time that a compilation is occurring. Ensures that the compiler's assumptions about pointer sizes and data align- ments are not in conflict with the data values that were in effect when the system libraries were created. The keywords for the -protect_headers option are as follows: Enables the protect headers feature. Disables the protect headers fea- ture. This is the default for all inputs. Cancels any previous -protect_headers options and places the compiler's default behavior in effect. If more than one such switch appears on the command line, only the last one is applied. See protect_headers_setup(8) for details. Two special names are understood by cpp. The name __LINE__ is defined as the current line number (as a decimal integer) as known by cpp, and __FILE__ is defined as the current file name (as a C string) as known by cpp. They can be used anywhere (including in macros) just as any other defined name. In addition, cpp reserves the names __DATE__ and __TIME__ for future use. All cpp directives start with lines beginning with #. The directives are: Replace subsequent instances of name with token-string. Notice that no space can be inserted between name and the "(" that follows it. Replace subsequent instances of name followed by a "(", a comma- separated list of unique identifiers, and a ")" with token-string, where each occurrence of an arg in the token-string is replaced by the corresponding identifier in the comma-separated list. When a macro with arguments is expanded, the arguments are placed into the expanded token-string unchanged. After the entire token-string has been expanded, cpp re-starts its scan for names to expand at the beginning of the newly created token-string. Cause the definition of name (if any) to be forgotten from this point. This directive is transformed by the preprocessor into the form __pragma(6, "string"). Include at this point the contents of filename (which will then be run through cpp). When the <filename> notation is used, filename is only searched for in the standard places. See the description of the -I option for more details. Cause cpp to generate line control information for the next pass of the C compiler. The integer-constant is the line number of the next line and filename is the file where it comes from. If filename is not specified, the current file name is unchanged. End a sec- tion of lines that begin with a test directive (#if, #ifdef, or #ifndef). Each test directive must have a matching #endif. Lines follow- ing this directive will appear in the output only if name has been the subject of a previous #define without being the subject of an inter- vening #undef. Lines following this directive will not appear in the output if name has been the subject of a previous #define without being the subject of an intervening #undef. Lines following this directive will appear in the output only if the constant-expression eval- uates to non-zero. All binary non-assignment C operators, the ?: operator, and the unary -, !, and ~ operators are all legal in constant- expression. The precedence of the operators is the same as defined by the C language. The unary operator defined can also be used in constant- expression in either of the following forms: defined(name) or defined name. This allows the utility of #ifdef and #ifndef in a #if directive. Only those operators, integer constants, and names that are known by cpp should be used in constant-expression. In particular, the sizeof operator is not available. For example, to test whether either of two symbols, foo and fum, are defined, use the following directive: #if defined(foo) || defined(fum) Reverses the notion of the test directive that matches this directive. For example, if lines pre- vious to this directive are ignored, the lines following will appear in the output. Similar to #else followed by #if, except does not introduce another conditional level. The same restrictions to the constant-expression for #if apply. For example: #if foo==4 a="foo is four"; #elif foo==2 a="foo is two"; #else a="foo is not four nor two"; #endif The test directives and the possible #else directives can be nested. Any number of #elif directives may occur between a test direc- tive and the corresponding #else or #endif. DESCRIPTION
The cpp C language preprocessor performs initial text substitutions, manipulations, conditional inclusion, and various other activities as described by the C standard. The preferred way to invoke cpp on C files is through the cc(1) command. See m4(1) for a general macro processor. The cpp preprocessor optionally accepts two file names as arguments: Input to the preprocessor Output from the preprocessor These files default to standard input and standard output if not supplied. Unless directed to do otherwise, cpp places the output file (ofile) in the same directory in which the input file (ifile) resides. The cpp preprocessor accepts C++-style end-of-line comments (//). This means that everything following the two slashes (//) to the end of the line in which they appear is considered to be a comment. NOTES
When newline characters were found in argument lists for macros to be expanded, previous versions of cpp put out the newlines as they were found and expanded. The current version of cpp replaces these newlines with blanks to alleviate problems that the previous versions had when this occurred. ERRORS
The error messages produced by cpp are intended to be self-explanatory. The line number and file name where the error occurred are printed along with the diagnostic. FILES
Standard directory for include files SEE ALSO
Commands: cc(1), as(1), m4(1) cpp(1)
All times are GMT -4. The time now is 04:17 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy