Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 07-03-2011, 05:32 PM   #1
LQ Newbie
Registered: Dec 2010
Posts: 16

Rep: Reputation: 0

I normally use 'grep' to provide parse out all unwanted extensions and so on by specifying the extension that I do want...
for example of I have list of files with many different extension types such as .dat, .txt, .pdf, ... and so on, and all I want to know are the .dat files, I use the following command:

cat "list.txt" | grep .dat
however, I know want to do the opposite, that is specify the extension that I do not want - that is to say that I want all extension types except for .dat...
what paramater must I specify in grep that will allow me to do this?
Old 07-03-2011, 05:49 PM   #2
LQ Addict
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,891

Rep: Reputation: 351Reputation: 351Reputation: 351Reputation: 351
See the grep man page. There is an option ( -v ) which inverts the match (match all except the given pattern).

cat "list.txt" | grep  -v .dat
1 members found this post helpful.
Old 07-03-2011, 08:31 PM   #3
Registered: Apr 2009
Distribution: debian gnu/linux
Posts: 798

Rep: Reputation: Disabled
You don't need to use `cat`:
grep pattern file
the dot needs to be escaped, else you match any single character with a dot
(if you escape it you match a dot literally):
grep  -v '\.dat' list.txt

Last edited by j1alu; 07-03-2011 at 08:33 PM.


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
[SOLVED] Grep -p for Linux, Trying to grep a paragraph. ohijames Linux - Newbie 5 07-22-2010 02:09 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
how to grep multiple filters with grep LinuxLover Linux - Enterprise 1 10-18-2007 07:12 AM
grep output on stdout and grep output to file don't match xnomad Linux - General 3 01-13-2007 04:56 AM
ps -ef|grep -v root|grep apache<<result maelstrombob Linux - Newbie 1 09-24-2003 11:38 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:25 PM.

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