LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
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
 
LinkBack Search this Thread
Old 05-02-2007, 11:44 PM   #1
ZAMO
Member
 
Registered: Mar 2007
Distribution: Redhat &CentOS
Posts: 565

Rep: Reputation: 30
how can i do cat?


hi Guys,

i want a command that must display the contents of a file???
cat=yes
but i want to avoid commented lines not to be displayed.anyway??
you know the big file like php.ini , i need to seacrch 1000 of lines. So , i want a command to display the contens of a file, which can output only non-commented lines.

Thanks in advance.
 
Old 05-02-2007, 11:50 PM   #2
jschiwal
Moderator
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,263

Rep: Reputation: 562Reputation: 562Reputation: 562Reputation: 562Reputation: 562Reputation: 562
You can use "grep -v" to remove lines containing the pattern of comments.

I don't use php, but if comments are lines beginning with '#', then
grep -v '^#' <filename> | less
will exclude commented lines.

You can add more exclusions like this:
grep -v -e '^#' -e '^!' | less
 
Old 05-03-2007, 12:11 AM   #3
ZAMO
Member
 
Registered: Mar 2007
Distribution: Redhat &CentOS
Posts: 565

Original Poster
Rep: Reputation: 30
sorry guru,

ITs working fine.

THanks a lot

Last edited by ZAMO; 05-03-2007 at 02:23 AM.
 
Old 05-03-2007, 02:07 AM   #4
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 13.37
Posts: 4,021

Rep: Reputation: 125Reputation: 125
That works on my system - what version of grep and what distro are you using? Your man page for grep will have info on whether you need to use an option to specify that your search is a regular expresision. On my system that would be:
Code:
grep -E -v '^#' <filename> | less
Also, do you have spaces at the start of the lines before the comment symbol?
 
Old 05-03-2007, 02:14 AM   #5
hashash
Member
 
Registered: Apr 2007
Posts: 31

Rep: Reputation: 15
well, prolly there is a space before the comment starts?
Would help if you posted some part of the file as is..

but seriously, you should be able to work on the nice lead by jschiwal.
All you have to do is find how to 'grep out' those lines. Since am too
lazy to look up the man pages for grep..

cat file | perl -pe 's/\s*#//'|less

or sed..

or you can use less'es 'not match' option and scroll line by line to entries that dont match a comment ..

or ...
 
Old 05-03-2007, 11:30 AM   #6
Indiestory
Member
 
Registered: Aug 2006
Location: Aberdeen, Scotland
Distribution: OpenBSD
Posts: 164
Blog Entries: 1

Rep: Reputation: 30
on my system atleast the -v option of grep removes anylines containing the following string, doesn't matter if theres space in front or not
 
Old 05-04-2007, 12:52 AM   #7
jschiwal
Moderator
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,263

Rep: Reputation: 562Reputation: 562Reputation: 562Reputation: 562Reputation: 562Reputation: 562
Quote:
Originally Posted by Indiestory
on my system atleast the -v option of grep removes anylines containing the following string, doesn't matter if theres space in front or not
If you only want to exclude lines that begin with #, then use ^ in the pattern. It is the beginning of line anchor.
 
  


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
cat in asm/ cat --show-all option Tux Linux - Software 1 09-02-2006 09:31 PM
Cat intervade Linux - Newbie 7 05-21-2006 02:18 PM
My Cat unimaginative General 71 02-18-2004 01:08 PM
Cat ... Beuzekom Linux - Newbie 4 01-19-2004 05:32 PM
regarding cat gui10 Linux - Security 6 12-07-2001 08:09 PM


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

Main Menu
 
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
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration