Skip to Content
Learning Linux Shell Scripting
book

Learning Linux Shell Scripting

by Ganesh Sanjiv Naik
December 2015
Beginner
306 pages
5h 2m
English
Packt Publishing
Content preview from Learning Linux Shell Scripting

Pattern searching using grep

The g/RE/p stands for globally search for the regular expression (RE) and print out the line.

Return status – success 0, pattern not found 1, file not found 2.

$  ps -ef | grep root

The preceding command will show all processes running currently whose user ID is "root".

$  ll /proc | grep "cpuinfo"

The preceding command will show the file with the name cpuinfo from the /proc directory.

$  grep –lir "text" *   // only file names  //   
$ grep –ir  "text" dir_name   // show lines of files //

We will try the following commands on the love.txt file:

Metacharacter

Function

Example

Description

^

Beginning-of-line anchor

'^mango'

Will display all lines beginning with mango

$

End-of-line anchor

'mango'$'

Will display ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning Linux Shell Scripting - Second Edition

Learning Linux Shell Scripting - Second Edition

Ganesh Sanjiv Naik

Publisher Resources

ISBN: 9781785286216