If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > awk/sed delete pattern from and to

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-23-04, 04:34
swamijc swamijc is offline
Registered User
 
Join Date: Oct 2004
Posts: 1
awk/sed delete pattern from and to

Hi,

Can any one help me out, My exact requirement is

For example
I need to read the file called abc.cpp and write it into new file called xyz.cpp while I write it should remove all comment line from abc.cpp.

Exp :

abc.cpp

include <stdio.h>
/* This is program is for
Identify Author access level */
void main()
{
int ja_Key; /* key for ALOT */
public rePaid()
{
cout<<”Test Script”;
} /* comment may come here */

}

In the above program

/* */ are comment line

My xyz.cpp program should be like that.


include <stdio.h>
void main()
{
int ja_Key;
public rePaid()
{
cout<<”Test Script”;
}
}

Thanks & Regards

K.Swaminathan


I have tryed with this command

sed

sed -e ':^/*:,:*e$:d' abc.cpp > xyz.cpp
error is :
sed: 0602-417 The label :^/*:,:*e$:d is greater than eight characters.

awk

$ cat RK
stuff I do not want
[string1]
I just want
these two lines
[string2]
more stuff I do not want
$ awk '/^\[string1\]/,/^\[string2\]/' rk
[string1]
I just want
these two lines
[string2]

I want to delete the content How to do that in awk

but I want to sort out /* .. */ string
Reply With Quote
  #2 (permalink)  
Old 10-24-04, 17:06
fla5do fla5do is offline
Registered User
 
Join Date: Oct 2003
Location: Germany
Posts: 138
HI swamijc,
try this :

# change to the path where your file exist
#cd
#cd bin
cat abc.ccp | awk ' BEGIN { FS="\n"; Comment="OFF" }
{
i=0
row=""
lang=length($1)
while ( i <= lang )
{
i=i+1
if ( substr($1,i,1) == "/" )
{
if ( substr($1,i+1,1) == "*" )
{
Comment="ON"
i=i+2
}
}
if ( substr($1,i,1) == "*" )
{
if ( substr($1,i+1,1) == "/" )
{
Comment="OFF"
i=i+2
}
}
if ( Comment=="OFF" )
{
row=row""substr($1,i,1)
}
}
if ( row != "" )
{
print row > "xyz.ccp"
}
}'
__________________
Greetings from germany
Peter F.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On