Results 1 to 3 of 3
how the grep command search when particular word is bing asked to search.what is the linking procedure to reach the particular word?...
- 07-25-2009 #1Just Joined!
- Join Date
- Jul 2009
- Posts
- 3
linking of grep command
how the grep command search when particular word is bing asked to search.what is the linking procedure to reach the particular word?
- 07-25-2009 #2
I am not the most knowledgeable person on this, but I can tell you how I have learned to use it.
I usually use it in conjunction with another command, to pick out a certain word that I am looking for. This is done by separating the commands with a vertical line or "pipe". A space must be on either side of the pipe.
I often use it to see which firmware is loading on a system. The output of the dmesg command would give this, but it is a lengthy output. by using grep, I can get only the info that I want.
When searching a text file for a word, use the cat command. I have blacklisted a wireless driver module, so to view if it actually is, I could do this:Code:dmesg | grep firmware
The output of that is this:Code:cat /etc/modprobe.d/blacklist.conf | grep ath
I hope this helps you some.Code:cat /etc/modprobe.d/blacklist.conf | grep ath blacklist ath_pci
Paul
Please do not send Private Messages to me with requests for help. I will not reply.
- 07-26-2009 #3Linux Guru
- Join Date
- Jan 2009
- Location
- Dover, NH
- Posts
- 1,633
Grep is a filter. It's purpose is to limit the output to only lines containing your search word. By linking, I think you are reffering to what we call a pipe (|) which "links" or "pipes" the output from one command into the input of another. This can be useful when searching for a particular file or better, exact command.
Say I want to know exactly what commands are available to me with the string "ed" in them. I could do a simple find with grep:
find / | grep ed
but then the output could be enormous and include all files with "ed", I just want commands, so then I pipe that output into grep again:
find / grep ed | grep bin
Now the ouput will only be commands (or at least files in a "bin" directory) that include "ed" as part of their name.
Now, in my case, I still ended up with a lot of stuff I didn't need, so there's another feature to grep, where you can invert it (don't show lines contining...)
find / | grep ed | grep bin\/ | grep -v bino | grep -v lib\/
example:
This also shows another feature, the escape character.Code:dcat@Server:~> find / | grep ed | grep bin\/ | grep -v bino | grep -v lib\/ /bin/ed /bin/sed /bin/setleds /opt/kde3/bin/digikamthemedesigner /opt/kde3/bin/feedbrowser /opt/kde3/bin/kcontroledit /opt/kde3/bin/kded /opt/kde3/bin/kdedoc /opt/kde3/bin/keditbookmarks /opt/kde3/bin/keditfiletype /opt/kde3/bin/keduca /opt/kde3/bin/keducabuilder /opt/kde3/bin/kfiledialog /opt/kde3/bin/kio_media_mounthelper /opt/kde3/bin/kio_media_realfolder /opt/kde3/bin/kmenuedit /opt/kde3/bin/kryptomedia /opt/kde3/bin/kspaceduel /opt/kde3/bin/noteedit /opt/picasa/bin/mediadetector /opt/picasa/wine/bin/regedit /opt/picasa/wine/bin/winedbg /opt/picasa/wine/bin/winedumpfontver /sbin/lvreduce /sbin/vgreduce /usr/bin/3Ddiag.ignoredb /usr/bin/beagled /usr/bin/btedit /usr/bin/ccmakedep /usr/bin/checkmedia /usr/bin/combinedeltarpm /usr/bin/devede /usr/bin/dh_undocumented /usr/bin/dvd+rw-mediainfo /usr/bin/ed /usr/bin/edit /usr/bin/edit-xml-catalog /usr/bin/editcap /usr/bin/editres /usr/bin/embedspu /usr/bin/exrmaketiled /usr/bin/fileschanged /usr/bin/freedup /usr/bin/frozen-bubble-editor /usr/bin/gccmakedep /usr/bin/gedi /usr/bin/gnome-desktop-item-edit /usr/bin/gnome-gen-mimedb /usr/bin/gst-feedback /usr/bin/gst-feedback-0.10 /usr/bin/gsvnsimplediff /usr/bin/gtkhtml-editor-test /usr/bin/gweled /usr/bin/hal-is-caller-locked-out /usr/bin/hal-is-caller-privileged /usr/bin/hp-timedate /usr/bin/icedax /usr/bin/ipod-read-sysinfo-extended /usr/bin/kded4 /usr/bin/kmenuedit /usr/bin/ldbedit /usr/bin/lilypond-invoke-editor /usr/bin/localedef /usr/bin/makedeltaiso /usr/bin/makedeltarpm /usr/bin/makedepend /usr/bin/makedvd /usr/bin/mcedit /usr/bin/mediasort.sh /usr/bin/movie-fakewavspeed /usr/bin/nm-connection-editor /usr/bin/nxredir /usr/bin/pamedge /usr/bin/pbmreduce /usr/bin/pcprofiledump /usr/bin/pdbedit /usr/bin/pdfedit /usr/bin/pfaedit /usr/bin/pgmedge /usr/bin/pm-is-supported /usr/bin/pnmscalefixed /usr/bin/psed /usr/bin/pstoedit /usr/bin/ptked /usr/bin/red /usr/bin/regedit /usr/bin/scrollkeeper-get-extended-content-list /usr/bin/sed /usr/bin/shred /usr/bin/sonic_reducer /usr/bin/sudoedit /usr/bin/tagmedia /usr/bin/tiffmedian /usr/bin/timed-read /usr/bin/timed-run /usr/bin/torcs-car-setup-editor /usr/bin/tred /usr/bin/updatedb /usr/bin/upssched-cmd /usr/bin/ustunts3dedit /usr/bin/ustuntstrackedit /usr/bin/winedbg /usr/bin/winedump /usr/bin/wired /usr/bin/xdbedizzy /usr/bin/xedit /usr/bin/xkbvleds /usr/bin/yuvmedianfilter /usr/local/bin/Ted /usr/sbin/aa-unconfined /usr/sbin/grub-install.unsupported /usr/sbin/gss_destroy_creds /usr/sbin/parted /usr/sbin/saned /usr/sbin/susedig.sh /usr/sbin/unconfined /usr/sbin/upssched /usr/share/dosemu/drive_z/bin/edit.cfg /usr/share/dosemu/drive_z/bin/edit.exe /usr/share/dosemu/drive_z/bin/edit.hlp /usr/share/dosemu/drive_z/bin/edlin.exe /usr/share/susehelp/cgi-bin/advancedsearch.cgi dcat@Server:~>
Often, special characters are ignored or interpreted different. A "\" in front of certain characters like space, "/" , "." , etc. will make them process litterally.
There's other useful features to grep as well, as in usually the search is case sensitive, but if you add "-i" then it will ignore the case.
man grep for more info.


Reply With Quote