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

5Perfect Linux three Musketeers sed

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

First, the use of the sed command: (good at text editing, good at manipulating lines)

1. Add information

two。 Delete information

3. Modify information

4. Filter information (grep is stronger)

2. View information

1) View the information according to the specified line number

Filter single line information to display the second line of information-n means to filter invalid information

Filter continuous multiple lines of information

Filter discontiguous multiple lines of information

3. View the information according to the specified content

Filter single line information

Filter continuous multiple lines of information

Filter discontiguous multiple lines of information

Summary: commands using the sed parameter

-n means to cancel the default output information

P for display information

4. Add information

1) add information according to the specified line

Indicates that information is inserted above line 2

Indicates the insertion of multiple rows,\ nindicates the branch

Indicates that information is inserted below line 2

Summary:

I means above the specified line

A means above the specified line

Similarly: according to the specified character increase information, change the number of lines to / character /, you can increase the information according to the character.

5. Delete the information:

1) delete the information according to the specified line

2) delete the information according to the specified character

Summary: all sed additions and modifications are made in memory and are only temporarily displayed on the screen. To write to the hard disk, add the parameter I.

But using the sed command to modify the contents of the file is best to make a backup first.

6. Modify the information:

Format: sed "s#xxx#xxx#g"

1) modify the information by the specified line

7. Exercises:

Exercise 1: create multiple users at once and set passwords at the same time

The first course: create a single user and set a password

Useradd stu01;echo '123456' | passwd-- stdin stu01

The second course: create multiple users and set passwords

Echo stu {01.. 10} | xargs-N1 | sed-r "s # (. *) # useradd\ 1bot echo '123456' | passwd-- stdin\ 1millig" | bash |

Exercise 2:

Change all .txt files in the oldboy01 directory to .jpg files

Note: be careful when using the sed command to share the-n and-I parameters, because-n means to cancel the default output

That often only shows the results you want to match when using-I to write to the hard disk or often the contents of the file only use the information you match, and all the other content is gone.

Exercise 3: get the ip address method:

Practice 4:sed to create users in batches, use dynamic passwords and save

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