User Tools

Site Tools


using_grep

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
using_grep [2016/09/06 19:34] walkeradminusing_grep [2023/03/09 22:35] (current) – external edit 127.0.0.1
Line 1: Line 1:
 ====== Using GREP ====== ====== Using GREP ======
 +<color darkorange>2016</color>
 +\\ 
 \\  \\ 
 \\  \\ 
Line 80: Line 82:
     grep -v bar /path/to/file     grep -v bar /path/to/file
 \\  \\ 
 +\\ 
 +===== UNIX / Linux pipes and grep command =====
 +grep command often used with shell pipes. In this example, <color red>show the name of the hard disk devices:</color>
 +\\ 
 +    dmesg | egrep '(s|h)d[a-z]'
 +    
 +    [    2.535530] sdhci: Secure Digital Host Controller Interface driver
 +    [    2.539697] sdhci: Copyright(c) Pierre Ossman
 +    [    2.542163] sdhost: log_buf @ bac46000 (fac46000)
 +    [    2.619698] mmc0: sdhost-bcm2835 loaded - DMA enabled (>1)
 +    [    2.691142] sdhci-pltfm: SDHCI platform and OF driver helper
 +    [    6.716496] bcm2835-wdt 3f100000.watchdog: Broadcom BCM2835 watchdog timer
 +    [    7.186573] brcmfmac: brcmf_sdio_drivestrengthinit: No SDIO Drive strength init done for chip 43430 rev 1 pmurev 24
 +\\ 
 +Display cpu model name:
 +\\ 
 +    cat /proc/cpuinfo | grep -i 'Model'
 +    
 +    model name      : ARMv7 Processor rev 4 (v7l)
 +    model name      : ARMv7 Processor rev 4 (v7l)
 +    model name      : ARMv7 Processor rev 4 (v7l)
 +    model name      : ARMv7 Processor rev 4 (v7l)
 +\\ 
 +However, above command can be also used as follows without shell pipe:
 +\\ 
 +    grep -i 'Model' /proc/cpuinfo
 +\\ 
 +\\ 
 +===== How do I list just the names of matching files? =====
 +Use the -l option to list file name whose contents mention main():
 +\\ 
 +    grep -l 'main' *.c
 +\\ 
 +\\ 
 +===== Force grep to display output in colours =====
 +Finally, you can force grep to display output in colors, enter:
 +\\ 
 +<color red>Raspbian seems to do this by default</color>
 +\\ 
 +    grep --color pi /etc/passwd 
 \\  \\ 
  
 +
 +    
          
  
using_grep.1473186888.txt.gz · Last modified: 2023/03/09 22:35 (external edit)