Visit Our UNIX and Linux User Community


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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to ignore single or multiple lines between /* and */ while reading from a file in unix?
# 1  
Old 06-07-2012
How to ignore single or multiple lines between /* and */ while reading from a file in unix?

I have a file proc.txt:
Code:
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 || '.' || @supp_db || '''' ||
  ' {select property, value, key_name
     from sys_suppdata
   where  key_name    = ''Approve_Deny_Description''
   or key_name     = ''Referral_Description'' }';
*/
-- Create SE Currency Table for Processing SE Results & Conversion
/* to prevent it from executing */

When reading this file thru shell script using the code below:

cat proc.txt | while read str
do
..
done

I want to ignore all the commented lines, whether single or multiple, i.e. between /* and */ and read all the other lines. Please suggest

Last edited by Franklin52; 06-07-2012 at 08:30 AM.. Reason: Please use code tags for data and code samples
# 2  
Old 06-07-2012
Code:
sed '/\/\*/,/\*\//d' filename

# 3  
Old 06-07-2012
Try something like this:
Code:
awk '/\/\*/{f=1} /\*\//{f=0;next} !f' proc.txt | while read str
do
  ...
done

# 4  
Old 06-07-2012
xbin - I tried your cmd earlier to even posting here. Actually sed will not work out if /* and */ fall in the same line. So the line

/* to prevent it from executing */

will not be deleted.

Franklin52 - i gave ur cmd in a ksh script and ran. It threw below error:

a.ksh:

Code:
#!/usr/bin/ksh
awk '/\/\*/{f=1} /\*\//{f=0;next} !f' /idn/home/pmylavar/proc/submon_se_cas_detail.sql | while read str
do
  echo "str is $str"
done

o/p:
Code:
awk: syntax error near line 1
awk: bailing out near line 1


Last edited by Franklin52; 06-07-2012 at 08:53 AM.. Reason: Please use code tags
# 5  
Old 06-07-2012
Quote:
Originally Posted by kidncute
Franklin52 - i gave ur cmd in a ksh script and ran. It threw below error:
....
Use /usr/xpg4/bin/awk or nawk on Solaris.
This User Gave Thanks to Franklin52 For This Post:
# 6  
Old 06-07-2012
Many thanks Franklin..It works with nawk:-)

Previous Thread | Next Thread
Test Your Knowledge in Computers #761
Difficulty: Medium
Every core of a multi-core CPU has a dedicated L1 cache and that cache is usually shared between the cores
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Reading multiple lines in a file

Hello, I am new in shell scripting. I need help regarding following. I have 4 files generated by backups daily. I have stored the names of these 4 files into one file. i.e I have 4 files names as a, b, c & d and these names have been put into one file abcd.txt. Now I want to cat each file in... (7 Replies)
Discussion started by: Ali Sarwar
7 Replies

2. Shell Programming and Scripting

Replacing a single line with multiple lines in a file

Hi Am confused with the usage of "sed" command I want to replace a single line with multiple lines of a file.. eg., A file has Hi, How are you? I need to replace as Am fine What are You doing? I used the script as string1="Hi, How are you?" echo "$string1 is the value"... (4 Replies)
Discussion started by: Priya Amaresh
4 Replies

3. Shell Programming and Scripting

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. 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... (1 Reply)
Discussion started by: neelmani
1 Replies

4. Shell Programming and Scripting

Awk match multiple columns in multiple lines in single file

Hi, Input 7488 7389 chr1.fa chr1.fa 3546 9887 chr5.fa chr9.fa 7387 7898 chrX.fa chr3.fa 7488 7389 chr21.fa chr3.fa 7488 7389 chr1.fa chr1.fa 3546 9887 chr9.fa chr5.fa 7898 7387 chrX.fa chr3.fa Desired Output 7488 7389 chr1.fa chr1.fa 2 3546 9887 chr5.fa chr9.fa 2... (2 Replies)
Discussion started by: jacobs.smith
2 Replies

5. Shell Programming and Scripting

Multiple lines in a single column to be merged as a single line for a record

Hi, I have a requirement with, No~Dt~Notes 1~2011/08/1~"aaa bbb ccc ddd eee fff ggg hhh" Single column alone got splitted into multiple lines. I require the output as No~Dt~Notes 1~2011/08/1~"aaa<>bbb<>ccc<>ddd<>eee<>fff<>ggg<>hhh" mean to say those new lines to be... (1 Reply)
Discussion started by: Bhuvaneswari
1 Replies

6. Shell Programming and Scripting

How to avoid the truncating of multiple spaces into a single space while reading a line from a file?

consider the small piece of code while read line do echo $line done < example content of example file sadasdasdasdsa erwerewrwr ergdgdfgf rgerg erwererwr the output is like sadasdasdasdsa erwerewrwr ergdgdfgf rgerg erwererwr the... (4 Replies)
Discussion started by: Kesavan
4 Replies

7. Shell Programming and Scripting

Split the single file lines into multiple files

Let's assume that I have a file name called ĎA' and it has 100 lines in it and would like to split these 100 lines into 4 files as specified bellow. INPUT: Input file name A 1 2 3 4 5 6 7 8 9 ........100 Output: 4 output files (x,y,z,w) File x should contains (Skip 4 lines)... (15 Replies)
Discussion started by: subbarao25
15 Replies

8. Shell Programming and Scripting

Reading Multiple Variables From a Single Line in Shell

I'm a Linux newb, I've been running a Debian Linux server for about a year now, and I've written some simple scripts to automate various things, but I still don't know much, and I forget what I learn as fast as I figure it out... Anyway, that really isn't important, I just want you to know that... (14 Replies)
Discussion started by: Drek
14 Replies

9. Shell Programming and Scripting

Reading multiple lines as single

Hi, Is it possible to read every 2 lines as single record, I have a file like below, ~CZK ~TSCHECHISCHE KRONE ~TSCHECH. REPUBLIK Dec 1 2005 12:00AM~ 10.840000~ ~DKK ~DAENISCHE KRONE ~DAENEMARK Dec 2 2005 12:00AM~ ... (9 Replies)
Discussion started by: braindrain
9 Replies

10. UNIX for Advanced & Expert Users

Reading lines within a Unix file.

I have a file that has a list of numbers in it. Each line has a different number. I am trying to create some sort of loop within a script that will pick the numbers up on lines 1 and 2 and then put those figures into the script. It then goes through the process then loops back and reads lines 2 and... (5 Replies)
Discussion started by: mariner
5 Replies

Featured Tech Videos