Sponsored Content
Top Forums Shell Programming and Scripting Quick and easy way to comment out multi lined print statements Post 302970646 by cokedude on Saturday 9th of April 2016 10:52:23 PM
Old 04-09-2016
Quote:
Originally Posted by Don Cragun
The description you have provided is a little sparse. If this is C or C++ code, the following two options might help:
  1. For the example shown, you could search for lines starting with arbitrary whitespace followed by printf( as the start line and continue to the next line ending with ); followed by arbitrary whitespace.
  2. If you're in vi at the start of the line containing printf you could use the % command to find the ending ) (assuming that the format string and any string constants being printed don't contain any mismatched parentheses).
If you're not already inside an editor making changes to your source code, you could use ed, ex, sed, or awk, to make similar changes (assuming you want to comment out ALL printf statements or only want to comment out printf statements with a specific format string).

But, if this is awk code (where the trailing semicolon is optional and in come cases the parentheses are also optional), different rules would be needed.


I have a lot of c code like this. I just put in a ridiculous amount of printf statements for debugging and I want to comment all of them out except the ones that contain "ACCEPT" and "REJECT"

Code:
            cmp_str9 = strcmp("return", strings_line_tokens[lower_bound_of_big_boy_counter ]);
            printf("4006 lower_bound_of_big_boy_counter %d \n", lower_bound_of_big_boy_counter);
            printf("4007 strings_line_tokens[lower_bound_of_big_boy_counter] %s \n", 
            strings_line_tokens[lower_bound_of_big_boy_counter]);
            //int
            if(cmp_str9 == 0)
            {
                printf("3402 checking return stuff \n");
                return_match_flag = 1;
                lower_bound_of_big_boy_counter++;
                get_function_type_for_proper_return(symbol_table_functions, type,id, 
                                         scope_char, symbol_table_functions_counter, function_type_for_proper_return);
                printf("3407 lower_bound_of_big_boy_counter %d \n", lower_bound_of_big_boy_counter);
                printf("3408 strings_line_tokens[lower_bound_of_big_boy_counter] %s \n", 
                strings_line_tokens[lower_bound_of_big_boy_counter]);
                printf("3410 function_type_for_proper_return %s \n", function_type_for_proper_return);

 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Notepad help needed easy quick question

TAKE A LOOK AT THE ATTACHED PICTURE. my goal is just to SELECT n DELETE Those lines : Dialogue: Marked=0,0:02:39.49,0:02:40.49,Default,NTP,0000,00 00,0000,!Effect, (without the text) take a look at that picture... the marked line... i just need ALL of these lines removed.. i managed... (3 Replies)
Discussion started by: mr_spidey
3 Replies

2. Shell Programming and Scripting

Help with for/if/else print statements

{for(i in b){if(b-1&&a!=b){print i";\t\t"b}else{print "NEW:"i";\t\t"b} } } what I need is to just print else{print "NEW:"i";\t\t"b and not print {print i";\t\t"b} how do i get awk to not print the first bit? is there an ignore statement although i still need awk to use this statement... (2 Replies)
Discussion started by: slashbash
2 Replies

3. Shell Programming and Scripting

Gawk - to extract values from multi lined file

Hi, I am new to awk and trying to extract some specific fields from the a large file. Can you please help me to write gawk code displaying the out put in the below format: Desired Output: name fallback_ip member member www-trymps.extlb.plstry.com-pool-1 180.254.112.50 ... (4 Replies)
Discussion started by: pratheeshp
4 Replies

4. Shell Programming and Scripting

Gawk - to extract values from multi lined file -I

Hi, Request your help in getting help with the below text formatting using awk. I am still learning awk and your help here is appreciated. Thanks in advance. Desireoutput ---------------- Virtual Pool Destination Profile Profile Profile Profile 1. virtual-1 pool-1 212.254.110.174:https... (2 Replies)
Discussion started by: pratheeshp
2 Replies

5. Shell Programming and Scripting

Extract values from multi lined url source

Hello, I want extract multi values from multi url source to a csv text. Thank you very much for help. my curl code : curl "http://www.web.com/cities//city.html Source code: div class="clear"></div> <table class="listing-details"> <tr> ... (1 Reply)
Discussion started by: hoo
1 Replies

6. Shell Programming and Scripting

awk Help: quick and easy question may be: How to use &&

Hi Guru's. I am trying to use to check if $5 is greater than 80 & if not 100, then to print $0 : awk '{ if ($5>80) && if ($5 != 100) print $0} But getting error: >bdf1|sed 's/%//g'|awk '{ if ($5>80) && if ($5 != 100) print $0}' syntax error The source line is 1. The error... (6 Replies)
Discussion started by: rveri
6 Replies

7. Shell Programming and Scripting

Sql multi line comment /* shell interpretation issue

Greetings Experts, I do have some basic knowledge of Unix. The task I am trying to do through shell script is to generate the view script for all of the tables which is in YYYYMMDD format (I assume I am on Ksh). I have certain tables that ends in YYYYMMDD format (eg: tbl_20150630) For each... (1 Reply)
Discussion started by: chill3chee
1 Replies

8. Shell Programming and Scripting

Generate print statements

I need to pickup values provided in braces from a file with many records I am able to get the count of number of dept's in each line .How do we write a logic to generate a print statement like below instead of using a while loop if the count is 0 it should generate awk -F'' '{print $2 }' ... (1 Reply)
Discussion started by: llazydev
1 Replies

9. UNIX for Beginners Questions & Answers

One Line Command how to use pipe statements to execute and comment on multiple possible outcomes

Hello Forum, I'm looking to expand the following command: INACTIVE_KERNELS=$(python -mplatform | grep -qi red && rpm -qa | grep '^kernel-' |grep -vE `uname -r` | paste -sd \; || echo "Not Red Hat Server") Currently this command will check if my server is RedHat server using the grep -qi... (6 Replies)
Discussion started by: greavette
6 Replies
All times are GMT -4. The time now is 01:00 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy