Magazine

The Basics of Regular Expressions in Linux Script

Posted on the 08 May 2021 by Satish Kumar @satish_kumar86

A sequence of characters that have certain patterns of text (with meta-characters) that are searched for in a larger text file are called regular expressions:

$ ll /proc | grep cpuinfo

In the preceding command, thegreputility will search for thecpuinfotext in all lines of input text and will print lines that have thecpuinfotext.

Utilities such asgrep,sed, and awkuse regular expressions for filtering text and then apply various processing commands as required by the user. The lines that do not match the pattern will be rejected. The following diagram explains the same concept:

regular expression linux concept

Back to Featured Articles on Logo Paperblog