Skip to Content
Mastering Linux Shell Scripting - Second Edition
book

Mastering Linux Shell Scripting - Second Edition

by Mokhtar Ebrahim, Andrew Mallett
April 2018
Beginner
284 pages
7h 3m
English
Packt Publishing
Content preview from Mastering Linux Shell Scripting - Second Edition

Ranges of characters

You can specify a range of characters to match between square brackets as follows:

[a-d]

This means the range of characters from a to d, so a, b, c, and d are included.

Let's use the same previous example file:

$ awk '/[a-m]ash/{print $0}' myfile$ sed -n '/[a-m]ash/p' myfile

The character range from a to m is selected. The third line contains r before ash, which is not in our range, so only the second line doesn't match.

You can use numbers ranges as well:

$ awk '/[0-9]/'

This pattern means from 0 to 9 is matched.

You can write multiple ranges in the same bracket:

$ awk '/[d-hm-z]ash/{print $0}' myfile$ sed -n '/[d-hm-z]ash/p' ...
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
Linux Shell Scripting Cookbook - Third Edition

Linux Shell Scripting Cookbook - Third Edition

Clif Flynt, Sarath Lakshman, Shantanu Tushar

Publisher Resources

ISBN: 9781788990554Supplemental Content