Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the differences between awk and sed in linux

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "what are the differences between awk and sed in linux". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what are the differences between awk and sed in linux?"

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 is often used for data slicing and data formatting; 3, sed generally operates on rows, and awk generally operates on columns.

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 and process text, and it has some syntax unique to programming languages, such as functions, branch loop statements, variables and so on. Of course, compared with our common programming languages, Awk is relatively simple.

2. Except that sed generally operates on rows, awk operates on columns

3. Sed: good at data modification. Awk: good at data slicing, data formatting, the most complex functions.

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

Awk is more suitable for formatting text, and the awk program operates on each line of the input file. Awk is an interpretive programming language. Text processing, output formatted text reports, perform arithmetic operations, perform string operations, and so on.

Expand knowledge:

With Awk, we can do the following:

1. Treat a text file as a text database consisting of fields and records

2, variables can be used in the operation of a text database

3, can use mathematical operations and string operations

4. Be able to use common programming structures, such as conditional branches and loops

5, can format the output

6, can customize the function

7, able to execute UNIX commands in awk scripts

8, able to process the output of the UNIX command

How sed works

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

2. When content enters the "mode space", the editing command of sed edits the content in the mode space (modify, replace, delete, append, display, etc.)

3. After the content editing in the mode space is completed, sed prints the content through the standard output (default is the display) and deletes the content in the mode space.

4. The first line of processing ends. The contents of the second line are re-read and processed until the last line.

Thank you for your reading, the above is "what is the difference between awk and sed in linux". After the study of this article, I believe you have a deeper understanding of the difference between awk and sed in linux, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report