RSS Feed

GREP


Features:

1. The ability to parse lines based on text and/or RegExes

2. Post-processor

3. Searches case-sensitively, by default

4. Searches for the text anywhere on the line

EX

1. grep ‘linux’ grep1.txt

2. grep -i ‘linux’ grep1.txt – case-insensitive search

3. grep ‘^linux’ grep1.txt – uses ‘^’ anchor to anchor searches at the beginning of lines

4. grep -i ‘^linux’ grep1.txt

5. grep -i ‘linux$’ grep1.txt – uses ‘$’ anchor to anchor searches at the end of lines

Note: Anchors are RegEx characters (meta-characters). They’re used to match at the beginning and end of lines

6. grep ‘[0-9]’ grep1.txt – returns lines containing at least 1 number

7. grep ‘[a-z]?’ grep1.txt

8. rpm -qa | grep grep – searches the package database for programs named ‘grep’

9. rpm -qa | grep -i xorg | wc -l – returns the number of pacakges with ‘xorg’ in their names

10. grep sshd messages

11. grep -v sshd messages – performs and inverted search (all but ‘sshd’ entries will be returned)

12. grep -v sshd messages | grep -v gconfd

13. grep -C 2 sshd messages – returns 2 lines, above and below matching line

14-. grep -c 2 sshd messages – returns count of lines

Note: Most, if not all, Linux programs log linearly, which means one line after another, from the earliest to the current

Note: Use single or double quotes to specify RegExes

Also, execute ‘grep’ using ‘egrep’ when RegExes are being used

Advertisements

About Ali abdo

Ali 32 years old from Egypt working as system engineer riding motorcycle to Support and develop Egyptian tourism, spread motorcycling.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: