LinuxQuestions.org
Help answer threads with 0 replies.
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 04-01-2009, 10:09 AM   #1
Nortekman
LQ Newbie
 
Registered: Oct 2008
Posts: 9

Rep: Reputation: 0
How to filter lines


What is the command to filter lines that have a certain "strings" in a file?
 
Old 04-01-2009, 10:16 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389
Hi,

Filter as in remove or as in show?

grep -v "whatever" infile -> removes all lines that contain whatever

grep "whatever" infile -> show all lines that contain whatever

Hope this helps.
 
Old 04-01-2009, 10:32 AM   #3
Nortekman
LQ Newbie
 
Registered: Oct 2008
Posts: 9

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by druuna View Post
Hi,

Filter as in remove or as in show?

grep -v "whatever" infile -> removes all lines that contain whatever

grep "whatever" infile -> show all lines that contain whatever

Hope this helps.
Thanks for your help druuna, that helped a lot!
 
Old 04-01-2009, 10:35 AM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Many utilities will do this---not just grep.

I suggest two references:
Bash Guide for Beginners--free at http://tldp.org

Classic Shell Scripting from O'Reilly --Any large bookstore, Amazon, etc.
 
  


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
Dansguardian - Won't filter new addresses added to filter list TechnoBod Linux - Software 1 01-08-2008 01:40 AM
filter out lines containing specific keywords from output kpachopoulos Linux - General 2 03-12-2007 08:29 PM
Is there a way to filter out all the comment lines in a configuration file... Akhran Linux - Newbie 3 12-07-2005 11:07 AM
Spam filter to external mail filter deadlock Linux - Software 1 06-16-2004 02:28 AM
How to filter lines from a text file Rascale Linux - Software 1 10-28-2003 12:46 PM

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

All times are GMT -5. The time now is 07:14 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration