Detailed explanation of Linux text processing tools

Detailed explanation of Linux text processing tools

1. Count the number of users whose default shell is not /sbin/nologin in the /etc/passwd file, and display all users

grep is a text tool that processes text by matching it line by line;
Use the grep command with the -v parameter to display non-matching lines;
getent passwd | grep -Ev /sbin/nologin$

2. Find the username, UID and shell type of the user with the maximum UID value

Sort is used for sorting. Adding specific parameters can be used to sort according to different requirements;
head user takes the first few lines;
cut is used to extract specific columns;
sort -k3 -t“:” -rn uses colon as separator and sorts the numbers in the third column in reverse order;
cut -d ":" -f1,3,7 uses colon as separator and takes columns 1, 3, and 7;

3. Count the number of connections for each remote host IP currently connected to this machine and sort them from largest to smallest.

Ss can check the number of local connections, and use grep to filter the established sessions; use tr - to compress; use cut to intercept the corresponding columns; use sort to sort; and use uniq to remove duplicate statistics.

4. Write a script createuser.sh to implement the following functions: use a user name as a parameter, if the user with the specified parameter exists, display its existence, otherwise add it; display the ID number and other information of the added user;

Read variables through the read command;
Judge through test;
Conditional selection through if;
Specify the exit code through exit;

5. Write a script that generates the basic format of the script, including author, contact information, version, time, description, etc.;

Edit the contents of vim.rc in the user added directory, and add corresponding information when creating a .sh script file;

This is the end of this article about the detailed use of Linux text processing tools. For more information on the simple use of Linux text processing tools, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Detailed explanation of regular expressions and three major text processing tools in Linux
  • A collection of linux text processing tools and regular expressions
  • Detailed explanation of sort command in Linux text processing tool
  • Detailed explanation of cut command in Linux text processing tool

<<:  WeChat applet records user movement trajectory

>>:  js to realize the mouse following game

Recommend

MySQL knowledge points for the second-level computer exam mysql alter command

Usage of alter command in mysql to edit table str...

Analyze the usage and principles of Vue's provide and inject

First, let's talk about why we use provide/in...

XHTML introductory tutorial: Use of list tags

Lists are used to list a series of similar or rela...

What is the function of !-- -- in HTML page style?

Mainly for low version browsers <!-- --> is ...

Example of how to configure cross-domain failure repair in nginx

Nginx cross-domain configuration does not take ef...

HTML Form Tag Tutorial (4):

Suppose now you want to add an item like this to ...

MySQL account password modification method (summary)

Preface: In the daily use of the database, it is ...

Vue implements scroll loading table

Table of contents Achieve results Rolling load kn...

MySQL turns off password strength verification

About password strength verification: [root@mysql...

Example of implementing GitHub's third-party authorization method in Vue

Table of contents Creating OAuth Apps Get the cod...

How to make vue long list load quickly

Table of contents background Main content 1. Comp...

Each time Docker starts a container, the IP and hosts specified operations

Preface Every time you use Docker to start a Hado...