how to ignore multiline comment from a file while reading it


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to ignore multiline comment from a file while reading it
# 1  
Old 07-16-2012
how to ignore multiline comment from a file while reading it

Hi friends , I want to ignore single and multiline comment( enclosed by " \* *\" ) of a file whle reading it. I am using the below code.

Code:
nawk '/\/\*/{f=1} /\*\//{f=0;next} !f' proc.txt | while read str
do
 ...
done

The problem is its working partially. that is its failing in one case.(shown below) i.e whenever there is a comment follwing a non comment in the same line, its deleting the whole line.

for example:
HTML Code:
select col1 , col2 
          from                                       /* selecting columns from the table1 */
                    table1;
 
if we run the above script on the above code it will remove 2nd line totally.

OUPUT:
HTML Code:
select col1 , col2 
        table1;
but the output should be :
HTML Code:
select col1 , col2 
          from                                     
table1;
please help. thanks in advance
# 2  
Old 07-16-2012
Try...
Code:
$ cat file1
:
select col1 , col2 from /* selecting columns from the table1 */ table1;
:
/* etc1
   etc2
*/
:
select col1 , col2
   from          /* selecting columns from the table1 */
     table1;
:

$ awk '{
          c = 0
          for (i = 1; i <= length; i++) {
              if (substr($0, i, 2)=="/*")
                   f = 1
              if (!f) {
                   printf substr($0, i, 1)
                   c++
              }
              if (substr($0, i, 2)=="*/") {
                   f = 0
                   i+=2
              }
          }
          if (!f && c)
              printf ORS
       }' file1 > file2

$ cat file2
:
select col1 , col2 from table1;
:
:
select col1 , col2
   from
     table1;
:

$

This User Gave Thanks to Ygor For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script using awk to find and replace a line, how to ignore comment lines

Hello, I have some code that works more or less. This is called by a make file to adjust some hard-coded definitions in the src code. The script generated some values by looking at some of the src files and then writes those values to specific locations in other files. The awk code is used to... (3 Replies)
Discussion started by: LMHmedchem
3 Replies

2. Shell Programming and Scripting

How to remove multiline HTML tags from a file?

I am trying to remove a multiline HTML tag and its contents from a few HTML files following the same basic pattern. So far using regex and sed have been unsuccessful. The HTML has a basic structure like this (with the normal HTML stuff around it): <div id="div1"> <div class="div2"> <other... (4 Replies)
Discussion started by: threesixtyfive
4 Replies

3. Shell Programming and Scripting

How to ignore single or multiple lines between /* and */ while reading from a file in unix?

I have a file proc.txt: if @debug = 1 then message 'Start Processing ', @procname, dateformat(now(*), 'hh:mm:ss'), @julian type info to client; end if; /* execute immediate with quotes 'insert into sys_suppdata (property, value, key_name) location ''' || @supp_server || '.' ||... (5 Replies)
Discussion started by: kidncute
5 Replies

4. Shell Programming and Scripting

convert Multiline file in one line file

Hi, Hi, we have one input file and file contain single line and multiline date. We want to convert multiline line in one line. Each file start with sequence of 000000001, 000000002, 000000003 so on. We want to convert the multiline line in one line. All (single line and converted multiline to... (6 Replies)
Discussion started by: humaemo
6 Replies

5. UNIX for Dummies Questions & Answers

multiline comment in shell script

Is thery any way to give comment to multiple line without explicitly specifying # at the begining of each line ? (2 Replies)
Discussion started by: hiten.r.chauhan
2 Replies

6. UNIX for Advanced & Expert Users

Problem of Multiline in csv file

Hi I have csv file which has test as multiline in the one column. ex. ---------data.csv------------ Seqno,EmpID,EmpName,Dept 1,123,"Vipin Agrawal","IT BUSINESS OFFSHORE" 2,124,"Simon Bhai","IT" The problem is name "Vipin Agrawal" has one new line character b/w name. same as Dept. ... (1 Reply)
Discussion started by: meetvipin
1 Replies

7. UNIX for Dummies Questions & Answers

Reading one line from a multiline string

Hi , I have a string which is of multiple line,I have to split the string by reading one line in each iteration and keep it in a string.I am keeping all the file names in side as string returned by the ls command ,I am stocked at the point of spliting the string to segragate each file. ... (4 Replies)
Discussion started by: Deekay.p
4 Replies

8. Shell Programming and Scripting

delete multiline string from file using sed.

Hi, I have file which has the following content... GOOD MORNING **********WARNING********** when it kicks from the kickstart, sshd daemon should start at last. (WHEN KICKING ITSELF, NOT AFTER KICKING). /etc/rc3.d/S55sshd ( run level specification for sshd is 55, now I would want to... (4 Replies)
Discussion started by: skmdu
4 Replies

9. Shell Programming and Scripting

help needed for multiline comment deleting script

Hi I have a script to delete the multiline comments as below ******************************************** #!/usr/bin/sed -f #Replaces single line comment s://.*:: #Replaces multiline comment present in a single line s:/\**\*/::g #Starting of the loop for checking the starting of the... (1 Reply)
Discussion started by: aster007
1 Replies

10. Shell Programming and Scripting

reading from a file and pass as variables and ignore # in the file

file.txt contains ------------------ sat1 1300 #sat2 2400 sat3 sat4 500 sat5 I need to write a shell script that will output like the below #output sat1.ksh 1300 sat3.ksh sat4.ksh 500 sat5.ksh my try ------- (4 Replies)
Discussion started by: konark
4 Replies
Login or Register to Ask a Question