First, use sed command :( good text editor, specializes in operations on the row)
1. increase information
2. Removal information
3. Modify information
4. Information filtering (grep stronger)
Practice sed command usage:
to view the information
1) according to the specified line number to view the information
filtering single-line information display second information line filter invalid information showing -n
Continuous multi-line message filtering
Filter discontinuous multi-line message
2) to view the information as specified content
Single-line filter information
Continuous multi-line message filtering
Filter discontinuous multi-line message
Summary: using sed command parameter
-n expressed cancel the default output
p denotes display information
Adding information
1) increase in the specified row information
indicates information inserted in the second line above
It represents insert multiple lines, \ n represents Branch
Insertion information indicates the second line below
Summary:
I indicates that the specified line above
a specified line represents the above
same reason: adding information according to the specified character to the number of rows / character / character can be increased according to information
To delete information:
1) delete information in accordance with the specified line
2) delete information in accordance with a specified character
Summary: sed all add, modify information is modified in memory, but temporarily displayed on the screen. I want to be written to disk to add this parameter
but modify the contents of the file using sed command a good idea to make a backup
Modify information: Format: Sed "S # XXX XXX # G #"
. 1) modifying information specified row
Exercise: create multiple users, and at the same time set the password
first course: to create a single user and set a password
useradd stu01; echo '123456' | passwd --stdin stu01
The second process: creating a plurality of users and choose a password
echo stu {01..10} | xargs -n1 | sed -r "s # # useradd \ 1; echo '123456' | passwd --stdin (*.) \ 1 # g "| bash
Exercise 2: .txt files in the directory oldboy01 all into .jpg files
Note: Be careful using sed -n command and -i parameter shared -n is canceled because the default output,
it often only shows the results when you want to match hard or often written using -i file content will only use your match out information, and other content no more
Method take ip address:
sed batch create users, the use of dynamic password and save