Advertisement
flycat

grep examples

Aug 14th, 2013 (edited)
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.91 KB | None | 0 0
  1. # Color highlithing with grep
  2. tail -f /var/log/mail | grep --color -E '<regex>|$'
  3.  
  4. # Print unvisible symbols
  5. LC_ALL="C" grep '^.*[^[:print:]]\+' имя_файла
  6.  
  7. # Multiple grep with xargs
  8. grep from.*linux.domain.tld /var/log/mail|awk '{print $6}'|xargs -I{} grep {} /var/log/mail|grep "client="|awk '{print $7}'|sort|uniq -c
  9.  
  10. # Extract all IP from log
  11. cat log.smbd*bz2|bunzip2|egrep -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'|sort -u
  12.  
  13. watch "smbstatus 2>/dev/null |egrep -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'|sort -u >tmp.log && cat smb-ip.log >> tmp.log && cat tmp.log|sort -u > smb-ip.log && cat smb-ip.log|wc -l && cat smb-ip.log"
  14.  
  15. # Search \t
  16. grep --perl-regex "CNAME\t${domain}"
  17.  
  18. # Print N strings after found:
  19. grep -A<N> "found" file
  20. # Print N strings before found:
  21. grep -B<N> "found" file
  22.  
  23. # Extract emails from file:
  24. grep -oe "[a-zA-Z0-9._]\+@[a-zA-Z]\+.[a-zA-Z]\+" emails.txt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement