Professional Documents
Culture Documents
Like
17
Tweet
pdfcrowd.com
pdfcrowd.com
The ^ matches the expression in the beginning of a line, only if it is the first
character in a regular expression. ^N matches line beginning with N.
pdfcrowd.com
From the above output you can come to know when all the kernel log has got
terminated. 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.
$ grep -c
open in browser PRO version
pdfcrowd.com
messages:0
anaconda.log:3
The above commands displays the count of the empty lines available in the
messages and anaconda.log files.
$ cat input
1. first line
2. hi hello
3. hi zello how are you
4. cello
5. aello
6. eello
7. last line
Now let us search for a word which has any single character followed by ello. i.e
open in browser PRO version
pdfcrowd.com
In case if you want to search for a word which has only 4 character you can give
grep -w . where single dot represents any single character.
pdfcrowd.com
messages.4:Jul 12 17:01:02 cloneme kernel: ACPI: PCI interrupt for device 0000:00:11.0 di
messages.4:Oct 28 06:29:49 cloneme kernel: ACPI: PM-Timer IO Port: 0x1008
messages.4:Oct 28 06:31:06 btovm871 kernel:
In the above example it matches for kernel and colon symbol followed by any
number of spaces/no space and . matches any single character.
$ cat input
open in browser PRO version
pdfcrowd.com
hi hello
hi
hihello
In the above example, the grep pattern matches for the pattern hi, followed by
one or more space character, followed by hello.
If there is no space between hi and hello it wont match that. However, * character
matches zero or more occurrence.
hihello will be matched by * as shown below.
hihello
$
open in browser PRO version
pdfcrowd.com
hi \?hello matches hi and hello with single space (hi hello) and no space (hihello).
The line which has more than one space between hi and hello did not get matched
in the above command.
pdfcrowd.com
$ grep "127\.0\.0\.1"
/var/log/messages.4
pdfcrowd.com
specified such as [a-z],[A-Z] etc. So the above command can also be written as
$ grep -i
"^[^aeiou]" /usr/share/dict/linux.words
1080
10-point
10th
11-point
12-point
16-point
18-point
1st
open in browser PRO version
pdfcrowd.com
First caret symbol in regular expression represents beginning of the line. However,
caret symbol inside the square bracket represents except i.e match except
everything in the square bracket.
10
Tweet
Like
17
Examples
pdfcrowd.com
pdfcrowd.com
linuxboy
dj
Cissy
pdfcrowd.com
LI NK
alok chaubey
Kashif
Worked for me but can you please tell how to grep % from the below
syntax
PING=$(ping -c 10 192.168.1.1 | grep -w
statistics|Time|100\\%|90\\%|80\\%|70\\%|60\\%|50\\%|40\\%|30\\%|20\
\%|10\\%)
I am doing this because I dont want a report if 10 packets are successfully sent
and there is 0% packet loss.
Thanks
open in browser PRO version
pdfcrowd.com
LI NK
Prasanna N
Ankit Gupta
kishore
open in browser PRO version
pdfcrowd.com
Nilesh
Kishore,
Theres -v option which inverts the search. So something like below should work.
grep -v ^$ filename
LI NK
amrutha
pdfcrowd.com
Anonymous
Vasanth
August 1 4, 201 4, 1 :1 7 pm
Hello Ramesh,
I really appreciate the effort you have taken in posting this on the Internet.
I have about 20 years of experience in the IT industry and I loved these
examples.
Thanks to you
LI NK
Vipin
pdfcrowd.com
LI NK
Sugan
saurabh
sumit
It was very helpful. Thank you for explaining. Could have been more
open in browser PRO version
pdfcrowd.com
Leave a Comment
Name
Website
Comment
pdfcrowd.com
Submit
Next post: 9 UNIX / Linux tput Examples: Control Your Terminal Color and
Cursor
Previous post: Happy New Year 2011 From Geek and the Doll
pdfcrowd.com
EBOOKS
Linux 101 Hacks 2nd Edition eBook - Practical Examples to Build a Strong Foundation in Linux
Bash 101 Hacks eBook - Take Control of Your Bash Command Line and Shell Scripting
Sed and Awk 101 Hacks eBook - Enhance Your UNIX / Linux Life with Sed and Awk
Vim 101 Hacks eBook - Practical Examples for Becoming Fast and Productive in Vim Editor
Nagios Core 3 eBook - Monitor Everything, Be Proactive, and Sleep Well
pdfcrowd.com
Like Page
Share
POPULAR POSTS
12 Amazing and Essential Linux Books To Enrich Your Brain and Library
50 UNIX / Linux Sysadmin Tutorials
50 Most Frequently Used UNIX / Linux Commands (With Examples)
How To Be Productive and Get Things Done Using GTD
30 Things To Do When you are Bored and have a Computer
Linux Directory Structure (File System Structure) Explained with Examples
Linux Crontab: 15 Awesome Cron Job Examples
Get a Grip on the Grep! 15 Practical Grep Command Examples
Unix LS Command: 15 Practical Examples
open in browser PRO version
pdfcrowd.com
pdfcrowd.com
CATEGORIES
Linux Tutorials
Vim Editor
Sed Scripting
Awk Scripting
Bash Shell Scripting
Nagios Monitoring
OpenSSH
IPTables Firewall
Apache Web Server
MySQL Database
Perl Programming
Google Tutorials
Ubuntu Tutorials
open in browser PRO version
pdfcrowd.com
PostgreSQL DB
Hello World Examples
C Programming
C++ Programming
DELL Server Tutorials
Oracle Database
VMware Tutorials
Ramesh Natarajan
Follow
pdfcrowd.com
C ON T A C T U S
Email Me : Use this Contact Form to get in touch
me with your comments, questions or suggestions
about this site. You can also simply drop me a line
to say hello!.
Follow us on Google+
Follow us on Twitter
Become a fan on Facebook
S UPPORT U S
Support this blog by purchasing one of my ebooks.
pdfcrowd.com
Copy right 2008201 5 Ramesh Natarajan. All rights reserv ed | Terms of Serv ice
pdfcrowd.com