LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 05-19-2011, 12:41 PM   #16
ramlubhai
LQ Newbie
 
Registered: May 2011
Posts: 2

Original Poster
Rep: Reputation: Disabled
Thumbs up


Thank you all for your answers. I will try the Vi fold comments suggestion first, I did not think that was possible.
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 05-19-2011, 04:42 PM   #17
onebuck
Moderator
 
Registered: Jan 2005
Location: Summer Midwest USA, Central Illinois, Winter Central Florida
Distribution: SlackwareŽ
Posts: 13,654
Blog Entries: 36

Rep: Reputation: 2844Reputation: 2844Reputation: 2844Reputation: 2844Reputation: 2844Reputation: 2844Reputation: 2844Reputation: 2844Reputation: 2844Reputation: 2844Reputation: 2844
Hi,

Quote:
Originally Posted by MTK358 View Post
The reason the OP wanted to remove comments is not because of HDD space, but because they're hard to scroll through in an editor.
Still not a good reason, comments are there for a reason. His/her system to choose/use as wish. But if you ever need to understand something then you will need to find the files again. The OP or for that matter anyone should learn to use a real editor like 'vi'.

Heck most editors page, so that should not be a big issue. Commenting out weighs the reasoning behind convenience of scrolling through a file.

But as I said, do as you wish it's yours to use anyway. Just poor habit to remove documentation for any form of using the system. Generally the comments are not always in-depth or specific enough.
 
Old 05-19-2011, 05:07 PM   #18
Telengard
Member
 
Registered: Apr 2007
Location: USA
Distribution: Kubuntu 8.04
Posts: 579
Blog Entries: 8

Rep: Reputation: 148Reputation: 148
Quote:
Originally Posted by catkin View Post
And empty lines:
Code:
grep -v "^#" < config.verbose | grep -v "^$" > config.terse
O RLY?

Code:
awk '/^[^#]/ && NF' config.verbose > config.terse
I didn't know about vi folding either
 
Old 05-20-2011, 12:42 AM   #19
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198
Quote:
Originally Posted by Telengard View Post
O RLY?

Code:
awk '/^[^#]/ && NF' config.verbose > config.terse
Thanks Telengard A single command is more elegant than a pipeline.
 
Old 05-20-2011, 07:22 AM   #20
Telengard
Member
 
Registered: Apr 2007
Location: USA
Distribution: Kubuntu 8.04
Posts: 579
Blog Entries: 8

Rep: Reputation: 148Reputation: 148
Quote:
Originally Posted by catkin View Post
Thanks Telengard A single command is more elegant than a pipeline.
Agreed, and you're welcome. But what I was really hoping for was someone to do one better than me :P

Last edited by Telengard; 05-20-2011 at 07:26 AM.
 
Old 05-20-2011, 12:08 PM   #21
trey85stang
Senior Member
 
Registered: Sep 2003
Posts: 1,091

Rep: Reputation: 41
Quote:
Originally Posted by Telengard View Post
Agreed, and you're welcome. But what I was really hoping for was someone to do one better than me :P
one of those games

sed "/ *#/d;/^$/d;/^#/d" some_file
 
0 members found this post helpful.
Old 05-20-2011, 01:32 PM   #22
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 722Reputation: 722Reputation: 722Reputation: 722Reputation: 722Reputation: 722Reputation: 722
Quote:
Originally Posted by trey85stang View Post
one of those games

sed "/ *#/d;/^$/d;/^#/d" some_file
"/^#/d" is unnecessary. "/ *#/d" already deletes lines beginnign with "#".

EDIT: Also, "/ *#/d" will delete non-comment text hat's followed by a comment!!! Like this:

Code:
non-comment text # this is a comment
This is how I would do it:

Code:
sed '/^[ \t]*#/d ; /^[ \t]*$/d'
It deletes blank lines, lines consisting only of whitespace, lines starting with "#", and lines that are only whitespace followed by a comment.

Last edited by MTK358; 05-20-2011 at 01:36 PM.
 
Old 05-20-2011, 03:14 PM   #23
trey85stang
Senior Member
 
Registered: Sep 2003
Posts: 1,091

Rep: Reputation: 41
good catch, I didnt realize the / *#/ would catch /^#/ also. Perhaps a GNU only thing? and I missed the ^

howeverr, a quick way to catch whitepaces altogether (tab included is [[:space:]])
Code:
$ cat file1
#Comment
  #indented comment with 2 spaces
	#indented comment with tab

end of file
Code:
$ sed "/^ *#/d" file1
random config file
	#indented comment with tab

end of file
Code:
$ sed "/^[[:space:]]*#/d;/^[[:space:]]*$/d" file1
random config file
end of file

Last edited by trey85stang; 05-20-2011 at 03:19 PM.
 
Old 05-20-2011, 04:09 PM   #24
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 722Reputation: 722Reputation: 722Reputation: 722Reputation: 722Reputation: 722Reputation: 722
Quote:
Originally Posted by trey85stang View Post
Perhaps a GNU only thing?
I don't understand.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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



Similar Threads
Thread Thread Starter Forum Replies Last Post
windows registry cleaner bigearsbilly General 13 03-03-2011 06:33 AM
Firefox Cleaner mlpa Linux - Software 2 08-01-2009 05:14 PM
Text Cleaner nlavon Linux - Software 2 06-10-2008 06:32 AM
Is there a neater way to do this? (bash script) Freemor Programming 8 04-02-2006 02:33 PM
MRU cleaner Ageless Linux - Software 0 04-26-2005 12:09 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:04 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration