Get the App
SLTechnology News&Howtos  ›  Servers  › 

Daily use of linux sed

Shulou Source: shulou.com Published: 2022-06-01 12:33:11 10月01日 Update

This article mainly explains "the daily use of linux sed". Friends who are interested may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "the daily use of linux sed".

Sed is a stream editor, and the sed editor processes the contents of the file one line at a time until the end of the file. The content being processed is stored in the pattern space (buffer), and the output or file is modified according to the option after the processing is completed.

Syntax format: sed [options]'[match pattern] command 'file

Common parameters:

-n cancel the default full output, as long as needed

-e allows multiple edits

-I modify the contents of the file

Command:

I (insert insert), insert the file I\ above the current line

A (append append), adding a line a\ after the current line

P print

D Delete

Match character set:

^ match line start

End of $matching line

1.1 matching printing

Sed-n 4p file # View the specified number of rows

1.2 add characters to the specified line

Sed-I "2i aaa\ nbbb" file

1.3 add commas

Sed-I "s / g" fiel # remove spaces

Sed-I ": a Ting Nathanz /\ nGrammer Magneol Universe GMP ba" plus a comma

1.4 string substitution

Regular replacement of sed's Universe BBG 'file #

Sed'/ cc/s/aa/bb/' file # match replacement

Sed'1 replacements 4sUniqqa _ BBG'# 1 to 4 lines

1.5 match deletion

Sed'/ aa/d' file # match deletion

Sed '1d3d' file # Delete 1 to 3 lines

Sed'/ ^ # / dscape / ^ $/ d' # Delete lines that start with # and blank

1.6 multiple edits (- e)

Sed-e '1mai 2d'-e's Unix AA Unix bb Unique 'file

1.7 add content at the end of the file

Sed-i.bak'$an aa' file

At this point, I believe you have a deeper understanding of "the daily use of linux sed". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Content file method usage line character processing command end pattern comma learning output practical deeper interest parameter string character set utility Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Docker Shulou Information Apple OPPO Reno