If you can see this check that

next section prev section up prev page next page

Searching for patterns in files using grep

You can instruct the Unix system to search through a file or files for a specific word, phrase, or group of characters by using the command grep (Globally search for a REgular expression and Print). For example to locate the word 'congested' in the file 'demofile' type the following:

% grep congested demofile

The output consists of all the lines in the file 'demofile' that contain the pattern for which you are searching. If the pattern contains multiple words or any character that conveys special meaning to the Unix system, such as (%,|,*,?, and so on), then the entire pattern must be enclosed in single quotes. For example to locate the lines containing the pattern 'the other thing to note' you would type the following:

% grep 'the other thing to note' demofile


Centos 7 intro: Paths | BasicShell | Search
Linux tutorials: intro1 intro2 wildcard permission pipe vi essential admin net SELinux1 SELinux2 fwall DNS diag Apache1 Apache2 log Mail
Caine 10.0: Essentials | Basic | Search | Acquisition | SysIntro | grep | MBR | GPT | FAT | NTFS | FRMeta | FRTools | Browser | Mock Exam |
CPD: Cygwin | Paths | Files and head/tail | Find and regex | Sort | Log Analysis
Kali: 1a | 1b | 1c | 2 | 3 | 4a | 4b | 5 | 6 | 7a | 8a | 8b | 9 | 10 |
Kali 2020-4: 1a | 1b | 1c | 2 | 3 | 4a | 4b | 5 | 6 | 7 | 8a | 8b | 9 | 10 |
Useful: Quiz | Forums | Privacy Policy | Terms and Conditions

Linuxzoo created by Gordon Russell.
@ Copyright 2004-2023 Edinburgh Napier University