LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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-09-2009, 08:31 PM   #1
yanghwanim
LQ Newbie
 
Registered: Mar 2009
Location: Honolulu, Hawaii
Distribution: CentOS/Fedora/Ubuntu/RedHat
Posts: 18

Rep: Reputation: 0
grep .....


The power of grep.....I'm trying to understand its use...can someone explain it to me?
 
Old 04-09-2009, 08:44 PM   #2
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,811
Blog Entries: 1

Rep: Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191
If you don't like grep man pages, please google it - there are A LOT OF tutorials on that subject.

edit: its general use is (as the man page says): to print lines matching a pattern

Last edited by sycamorex; 04-09-2009 at 08:46 PM.
 
Old 04-09-2009, 08:46 PM   #3
cheftec
Member
 
Registered: Jan 2009
Location: Pennsyltucky
Distribution: Debian, Ubuntu, DeLiLinux, others
Posts: 144

Rep: Reputation: 19
http://www.ss64.com/bash/grep.html

Read that. On your level as a newbie, you'll pretty much just use it as a specifier. For example, if you

ps -A | grep firefox

you're asking the computer to give you a list of all the processes running (ps -A) but then to only show (with grep) the ones that have firefox in the name of the process.
 
Old 04-10-2009, 12:21 AM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
And for finding strings in files:

grep <string_to-find> <file(s)-to-search>

eg

grep zxc test.dat

find all lines with 'zxc' in file test.dat

most popular switch is -i -> case-insensitive matching ie

grep -i zxc test.dat

matches 'zxc' or 'Zxc', or 'ZXc' etc etc ...
 
Old 04-10-2009, 02:08 AM   #5
mahajan.girish
LQ Newbie
 
Registered: Apr 2009
Location: Mumbai, India
Posts: 1

Rep: Reputation: 1
Thumbs up try grep -v

Dude, suppose u have x lines of data in sample.txt file, out of which some of the lines contains "temp" keyword , and if u want to skip that all lines contens temp, then try

cat sample.txt | grep -v "temp"

it will show only tht lines that doesnt contain temp word...

Cheers J!
 
Old 05-28-2009, 06:34 PM   #6
yanghwanim
LQ Newbie
 
Registered: Mar 2009
Location: Honolulu, Hawaii
Distribution: CentOS/Fedora/Ubuntu/RedHat
Posts: 18

Original Poster
Rep: Reputation: 0
Thanks for the links, and help! I now understand Grep!

Thanks!
 
  


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
Trying to understand pipes - Can't pipe output from tail -f to grep then grep again lostjohnny Linux - Newbie 15 03-12-2009 11:31 PM
how to grep multiple filters with grep LinuxLover Linux - Enterprise 1 10-18-2007 08:12 AM
grep output on stdout and grep output to file don't match xnomad Linux - General 3 01-13-2007 05:56 AM
bash script with grep and sed: sed getting filenames from grep odysseus.lost Programming 1 07-17-2006 12:36 PM
ps -ef|grep -v root|grep apache<<result maelstrombob Linux - Newbie 1 09-24-2003 12:38 PM


All times are GMT -5. The time now is 06:41 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