Home  >  Article  >  Operation and Maintenance  >  What is the difference between awk and sed in linux?

What is the difference between awk and sed in linux?

WBOY
WBOYOriginal
2022-05-17 17:05:423628browse

The difference between awk and sed in Linux: 1. sed is a non-interactive and character stream-oriented editor, awk is a pattern matching programming language; 2. sed is often used for data modification, awk Commonly used for data slicing and data formatting; 3. sed generally operates on rows, and awk generally operates on columns.

What is the difference between awk and sed in linux?

#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.

What is the difference between awk and sed in Linux

1. sed is a non-interactive and character stream-oriented editor (a “non-interactive” stream-oriented editor)

Awk is a pattern matching programming language because its main function is to match text and process it. At the same time, it has some syntax that is unique to programming languages, such as functions, branch loop statements, variables, etc. Of course, compared to our common programming languages, Awk is relatively simple

2. In addition to sed, which generally operates on rows, awk operates on columns

3. sed: good at data modification. awk: good at data slicing and data formatting, with the most complex functions.

sed (full name: Stream Editor) is good at modifying data in files and is very efficient. Here is a summary of some basic usage of additions, deletions and modifications.

awk is more suitable for formatting text and performing more complex format processing on text. The awk program operates on each line of the input file. awk is an interpreted programming language. Text processing, outputting formatted text reports, performing arithmetic operations, performing string operations, etc.

Extended knowledge:

Using Awk, we can do the following things:

1. Treat the text file as a text database composed of fields and records;

2, be able to use variables in the process of operating text databases;

3, be able to use mathematical operations and string operations

4, be able to use common programming structures, such as Conditional branches and loops;

5, can format output;

6, can customize functions;

7, can execute UNIX commands in awk scripts;

8, capable of processing the output of UNIX commands;

The working principle of sed

What is the difference between awk and sed in linux?

-1. When using the sed command to process text , sed first reads the first line of the object's text file into the pattern space.

2. When content enters the "pattern space", sed's editing command performs editing operations (modify, replace, delete, append, display, etc.) on the content in the pattern space.

3. After the editing and processing of the content in the pattern space is completed, sed prints the content through the standard output (default is the monitor) and deletes the content in the pattern space.

4. The first line of processing is completed. Read the contents of the second line again and process them until the last line.

Recommended learning: Linux video tutorial

The above is the detailed content of What is the difference between awk and sed in linux?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn