LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-17-2018, 05:43 AM   #1
sigint-ninja
Member
 
Registered: Feb 2011
Location: Republic Of Ireland
Distribution: Debian,Centos,Slackware
Posts: 508

Rep: Reputation: 29
what does grep -v '#' do?


does this command include or exclude comments starting with #
and sort them in reverse?
 
Old 08-17-2018, 05:46 AM   #2
un1x
Member
 
Registered: Oct 2015
Posts: 645

Rep: Reputation: Disabled
Code:
~$ grep -v 
Usage: grep [OPTION]... PATTERN [FILE]...
Try 'grep --help' for more information.
Code:
$ grep -v #
Usage: grep [OPTION]... PATTERN [FILE]...
Try 'grep --help' for more information.
'grep --help' is u friend !

Last edited by un1x; 08-17-2018 at 05:50 AM.
 
Old 08-17-2018, 05:50 AM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 18,127

Rep: Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921
My first reaction was "read the manpage".
Code:
-v, --invert-match
              Invert the sense of matching, to select non-matching lines.
Now I see that "invert" may be causing confusion. The important bit is "to select non-matching lines."
grep normally returns matching lines, this is the inverse. Nothing to do with inverting (reverse sorting) the results.
 
Old 08-17-2018, 06:24 AM   #4
mddnix
Member
 
Registered: Mar 2013
Distribution: Redhat, Ubuntu
Posts: 537

Rep: Reputation: 149Reputation: 149
Quote:
Originally Posted by sigint-ninja View Post
does this command include or exclude comments starting with #
and sort them in reverse?
It excludes any line which has # in its line. Not just at the beginning.

To exclude # that is at the beginning, use

Code:
grep -v '^#'
 
Old 08-21-2018, 04:20 PM   #5
sigint-ninja
Member
 
Registered: Feb 2011
Location: Republic Of Ireland
Distribution: Debian,Centos,Slackware
Posts: 508

Original Poster
Rep: Reputation: 29
thanks all
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
from ps -ef | grep java how can I grep out Xms & Xmx value hjo99729 Linux - Newbie 3 10-26-2017 07:39 PM
Find & grep - how to return pathes, not grep phrases ? postcd Linux - General 2 11-25-2014 12:43 PM
Creating an alias in ksh that uses grep and includes 'grep -v grep' doug248 Linux - Newbie 2 08-05-2012 02:07 PM
Trying to understand pipes - Can't pipe output from tail -f to grep then grep again lostjohnny Linux - Newbie 15 03-12-2009 10:31 PM
ps -ef|grep -v root|grep apache<<result maelstrombob Linux - Newbie 1 09-24-2003 11:38 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:14 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration