Book Image

Linux Shell Scripting Essentials

Book Image

Linux Shell Scripting Essentials

Overview of this book

Table of Contents (15 chapters)
Linux Shell Scripting Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

The Cut-based selection


We can also select a text from each line of single/multiple files using the cut command. The cut command allows us to select a column based on delimiters. By default, TAB is used as delimiter. We can also select a portion of the text in a line by specifying the characters or range. The syntax is as follows:

cut OPTION [FILE …]

The cut command works on the single and multiple files. By default, the output is printed on stdout.

The options for the cut command are explained in the following table:

Option

Description

-b LIST

This selects bytes that are specified in LIST.

-c LIST

This selects characters that are specified in LIST.

-d DELIM

This uses delimiter as DELIM instead of TAB. It also prints lines that don't have a delimiter.

-f LIST

This only selects fields specified in LIST.

--complement

This complements a set of selected bytes, characters, or fields.

-s

Don't print lines that don't have a delimiter.

--output-delimiter=STRING

This uses...