regular expression to match comments in C
my task is to retrieve a certain pattern from c source code , but the i don't need the comments, so i have to remove them.
----------------the first question----------------- i have done some processing , the code and the matched pattern are in the same line, i need to match the comments and remove them. the example goes as follows: /*******abc*****/ int j = 0; /***abc/cde****/ int i = 3; all my work is done is in bash script, so your help in bash script is much appreciated. i have already got this one : awk '{gsub("/\\*[^/]*\\*/","");print}' but it cannot process the second comment in the example. so could you give me some help? can I use / and * altogether as one search symbol? ----------------the second question----------- i need to use commas to separate the code line. but some lines confuses me : foo ("abc, dec" "we are here", 1, "true"); i need to retrieve the the string "abc, dec we are here", the comma cause me headache. could you give me some help? thanks a lot. |
Your first problem has 2 issues:
1. awk can use either // to search for a regex or "" to compute a regex. You have used both 2. You are not looking for the unique item to exclude or better way to say it is remove so many lots of not this. Code:
awk 'gsub(/\/[^ ]*/,"")' some finagling. |
All times are GMT -5. The time now is 11:36 AM. |