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

How to use sed of Linux

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

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to use Linux's sed". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to use Linux's sed.

Sed is a text processing tool that adds, replaces, deletes data according to specified conditions.

-an append to add one or more lines after the current line

-c line replacement replace the original data row with the string after c

-I insert, insert one or more rows in the current row

-d Delete the specified line

-p print out the specified line

The-s string substitution replaces one string with another in the format "line range s / old string / new string / g", which is similar to the replacement format in vim.

# p print command

Sed-n "p" passwd

# locate the line

# sed-n "10p" passwdoperator:x:11:0:operator:/root:/sbin/nologin# sed-n "/ root/p" passwdroot:x:0:0:root:/root:/bin/bashoperator:x:11:0:operator:/root:/sbin/nologin

Row interval

# cat passwd | sed-n '10pm 20p'

# a New Line

# nl passwd | sed '5aMui'

# I insert rows

Nl passwd | sed'5i Murray'

# c replace

Nl passwd | sed'5c replace current line'

# d Delete

Sed '1d' passwd # Delete the first row of data sed' 2Magazine 4d' passwd # Delete 2d4 rows of data # nl passwd | sed'/ mysql/ d' # Delete matching mysql data here, I believe you have a deeper understanding of "how to use 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!

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

Internet Technology

Wechat

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

12
Report