The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
delete comments susau_79 Shell Programming and Scripting 10 08-03-2009 02:28 AM
how can i remove comments in random positions in a file?(bash) bashuser2 Shell Programming and Scripting 2 05-02-2009 05:47 AM
AWK to skip comments in XML file majormark Shell Programming and Scripting 1 10-29-2008 06:30 AM
Add Comments to the specifi lines i na file ukatru UNIX for Advanced & Expert Users 1 09-21-2008 08:39 AM
removing comments from file skully Shell Programming and Scripting 9 06-08-2008 09:44 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 2 Weeks Ago
aadi_uni aadi_uni is offline
Registered User
  
 

Join Date: Oct 2009
Posts: 15
Delete Comments in file

How can I delete comments (lines beginning with /* and ending with */) in file?
with single command line..My suggestion is to use grep and sed!
  #2 (permalink)  
Old 2 Weeks Ago
jpradley jpradley is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 50
You don't need grep. Sed alone will do the job.
  #3 (permalink)  
Old 2 Weeks Ago
juststarted juststarted is offline
Registered User
  
 

Join Date: Nov 2009
Posts: 7
sed command to remove comments

Hello,

i am replying rather old post, but i have the similar problem with slight variation.

when i use command:

sed '/*,*/d' somefile.c

suppose the file somefile.c contains
line

/* this is an example */

its removing comeplete line but when i have a line

/*
this is an example
*/
its removing only /* and */
and not the text between /* and */

i can easily implement the commad using command line arguments.
but i want to know is there any command that deletes the entire characters present under /* and */ when they are in different lines.

Thanks,
  #4 (permalink)  
Old 2 Weeks Ago
binlib binlib is offline
Registered User
  
 

Join Date: Aug 2009
Location: New Jersey
Posts: 61
From http://sed.sourceforge.net/grabbag/t...t_with_sed.txt
Code:
!/usr/bin/sed -f

# if no /* get next
/\/\*/!b

# here we've got an /*, append lines until get the corresponding
# */
:x
/\*\//!{
N
bx
}

# delete /*...*/
s/\/\*.*\*\///
  #5 (permalink)  
Old 2 Weeks Ago
thegeek thegeek is offline
Registered User
  
 

Join Date: Apr 2009
Location: /usr/bin/vim
Posts: 447
If you are looking for a solution from other sed & awk then, look at CLOC.

CLOC -- Count Lines of Code
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:27 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0