13 Regular Expression with Grep Command RHCSA - Tech Arkit
1. Check Grep version
grep -V
2. Search single word in single file / multifles
grep string *
3. Search Multiple words in single file / multiple files
grep -E 'word1|word2'
4. Seach text which is not maching to string
grep -v "String" fileName
5. Print the matching string and its before lines
grep ens33 -A 4
6. Print the matching string and its after lines and its around lines
grep enss33 -B 4
grep ens33 -C 4
7. Search a string Recursively
grep -r string fileName
8. Grep the string with highlighted in color
grep --color=auto string file Name
export GREP_COLOR='1;30;43'
9. display the lines which does not matches all the given strings
grep -v -e "a" -e "b" -e "c" filename.txt
10. Get the count of given string from file
grep -c string filename
11. Search for files which are matching to the given string
grep -l this demo*
12. Beginning of line ^ using cap symble
grep "^Nov 10" messages.1
13. End of the line $ using dollar symble
grep "terminating.$" messages
? The preceding item is optional and matched at most once.
* The preceding item will be matched zero or more times.
+ The preceding item will be matched one or more times.
n The preceding item is matched exactly n times.
n, The preceding item is matched n or more times.
,m The preceding item is matched at most m times.
n,m The preceding item is matched at least n times, but not more than m times.
From the above output you can come to know when all the messages has got interrupt. Just like ^ matches the beginning of the line only if it is the first character, $ matches the end of the line only if it is the last character in a regular expression.
Youtube PlayLists
Shell-Scripting: https://goo.gl/a1Hu3s
Linux-Commands: https://goo.gl/QDoL7h
RHCSA Certification: https://goo.gl/X2Ksqn
Putty Software Tricks: https://goo.gl/MB1Do2
Linux OS: https://goo.gl/62p8s9
Follow Us on Social Media
Telegram Group: https://goo.gl/KPvMda
https://arkit.co.in/one-linux-tutorial/
Reddit: http://bit.ly/redditark
https://goo.gl/mcUvef
Mailing List: http://bit.ly/feedburnerark
https://goo.gl/fb/WAU7JG
Facebook: https://fb.com/linuxarkit
https://goo.gl/2QN4sD
LinkedIn: http://bit.ly/linkedark
https://goo.gl/ZLcikC
Twitter: https://twitter.com/aravikumar48
Google Plus: http://bit.ly/gplusark
https://goo.gl/79zwX9
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment