- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Regular expression query !!should be a good one
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-06-2001 02:47 AM
тАО07-06-2001 02:47 AM
I have a definition in my file
int func(/* sdsd*/int a, /*deep*/char b);
I need to change it to
int func( int a, char b);
or
int func(int a,char b);
Basically, I need to get rid of the comments in the line.
Is there a regular expression substitution for this.
Also Note in "vi" I tried:
:%s/\/\*.*\*\///g
I tired may other patterns with "(" and ")" stuff, but somehow did not work.
Got any idea, please let me know.
Thanks and Regards
Deepak
Solved! Go to Solution.
- Tags:
- regex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-06-2001 02:59 AM
тАО07-06-2001 02:59 AM
Re: Regular expression query !!should be a good one
you just provided one DOT. So only any comment consisting of a single char will be replaced.
I am not so deep in regexps, but I would try
%s/\/\*.\*\///g
%s/\/\*..\*\///g
%s/\/\*...\*\///g
and so on (yes, not very sophisticated)...
Volker
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-06-2001 03:12 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-06-2001 03:34 AM
тАО07-06-2001 03:34 AM
Re: Regular expression query !!should be a good one
:%s;/\*[^\*]*\*/;;g
or
:%g;func;s;/\*[^\*]*\*/;;g (for only the lines containing "func")
should work too; by replacing the seperator by ";" you don't need to escape the "/" in your search.
BTW: s;/\*.*\*/;... will replace everyting between the first "/*" and the last "*/" on a line !!
regards,
Thierry.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-06-2001 05:00 AM
тАО07-06-2001 05:00 AM
Re: Regular expression query !!should be a good one
The seems to be some problem, my commets cannot have '*' or '/'
e.g.
int func1( /* *sdf */ int *a ,/* */int b);
This is a valid C statement.
Can Anyone handle this as well ?
Thanks and Regards
Deepak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-06-2001 05:24 AM
тАО07-06-2001 05:24 AM
Re: Regular expression query !!should be a good one
:%s;/\*[^/]*\*/;;g
will allow "*" in your comments, but no "/" :)
So if you run both substitutes, everything should be OK.
:%s;/\*[a-bA-Z0-9*/.:\; ]*\*/;;g
will do the trick in one step, add any character you need between the square brackets.
good luck,
Thierry.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-06-2001 06:00 AM
тАО07-06-2001 06:00 AM
Re: Regular expression query !!should be a good one
:%s;/\*[a-bA-Z0-9*/.:\; ]*\*/;;g
did not work fine for me .
e.g. int func1( /* sdf / *ddd */ int *a ,int b);
is the input.
There has to be way..
Thanks and Regards
Deepak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-06-2001 06:32 AM
тАО07-06-2001 06:32 AM
Re: Regular expression query !!should be a good one
perl -p -i -e 's{/\*.*?\*/}{}' yourprog.c
The .*? will only match until the FIRST */ is found.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-06-2001 10:38 AM
тАО07-06-2001 10:38 AM
Re: Regular expression query !!should be a good one
try this with sed(1):
/func/ s#\(^.*\)\(\/\*..*\*\/\)\(.*\)\(\/\*..*\*\/\)\(.*$\)#\1 \3 \5#g
\(^.*\) starts matching the front
of input lines
\(\/\*..*\*\/\) matches the comment you
want to discard (at least
one character e.g. "/* */")
\(.*\) captures the text between
comments
\(\/\*..*\*\/\) matches the second comment
WARNING: _requires_ second cmnt
\(.*$\) captures text up to the end
of the line
\1 \3 \5 recalls what was matched by
those parenthetical statements
numbered starting with 1 from
left to right
Again, this statement will "hit" only on lines
that have two embedded comments.
Enjoy,
-dlt-
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-06-2001 01:30 PM
тАО07-06-2001 01:30 PM
Re: Regular expression query !!should be a good one
Can someone tell me what you are talking about?
thanks
Richard