Skip to Content
Linux Command Line and Shell Scripting Bible, 4th Edition
book

Linux Command Line and Shell Scripting Bible, 4th Edition

by Richard Blum, Christine Bresnahan
January 2021
Intermediate to advanced content levelIntermediate to advanced
832 pages
18h 3m
English
Wiley
Content preview from Linux Command Line and Shell Scripting Bible, 4th Edition

APPENDIX BQuick Guide to sed and gawk

If you do any type of data handling in your shell scripts, most likely you'll need to use either the sed program or the gawk program (and sometimes both). This appendix provides a quick reference for sed and gawk commands that come in handy when working with data in your shell scripts.

The sed Editor

The sed editor can manipulate data in a data stream based on commands you either enter into the command line or store in a command text file. It reads one line of data at a time from the input and matches that data with the supplied editor commands, changes data in the stream as specified in the commands, and then outputs the new data to STDOUT.

Starting the sed editor

Here's the format for using the sed command:

sed options script file

The options parameters allow you to customize the behavior of the sed command and include the options shown in Table B.1.

TABLE B.1 The sed Command Options

Option Description
‐e script Adds commands specified in script to the commands run while processing the input
‐f file Adds the commands specified in the file file to the commands run while processing the input
‐n Doesn't produce output for each command but waits for the print command

The script parameter specifies a single command to apply against the stream data. If more than one command is required, you must use either the ‐e option, to specify them ...

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

Linux Command Line and Shell Scripting Bible, 3rd Edition

Linux Command Line and Shell Scripting Bible, 3rd Edition

Christine Bresnahan, Richard Blum

Publisher Resources

ISBN: 9781119700913Purchase Link