Linux common text processing commands and vim text editor

Linux common text processing commands and vim text editor

Today, let's introduce several common text processing commands and vim text editor

day3--Common text processing commands and vim text editor

col, used to filter control characters, -b filters out all control characters. This command is not commonly used, but you can use man command name | col -b >help.txt

Export a help document. | is a pipe character, which is used to send the previous execution result to the next one through a "pipe"

man ls | col -b > ls_help #Export the help document of ls command

The cut command cuts bytes from each line and writes them to standard output.

cut -b #Split by byte cut -b "1,3" #Output the first and third bytes cut -c #Split by character cut -d #Define the delimiter, need to be used with -f cut -f #Use with -d to output fields cut -output-delimiter='delimiter' #Replace the delimiter with your own delimiter

wc statistics command

wc -c #Display the number of bytes wc -l #Display the line number wc -w #Display the number of words

Exercise: Use the pipe character wc command and the cut command to count the number of characters in a file and print it to the screen

echo command, output

echo -n # output without line break

head -n, view the first n lines of a file, the default is 10 lines

tail -n, view the last n lines of a file, the default is 10 lines

Exercise: Use head and tail with the pipe character to output the last 10 to 15 lines of /var/log/message

cat View file information

more displays file information page by page. The space key is the next page, and the b key will go back one page.

less, use less to browse files at will

sort

sort -b #ignore spaces at the beginning of each line sort -c #check if the files are sorted in order sort -f #treat lowercase letters as uppercase letters sort -o output file #store the results into a specified file sort -r #sort in reverse order sort -n #sort by numerical value sort -t delimiter #specify delimiter

Example:

uniq removes duplicate lines

Example: (The number in front indicates how many times it appears)

When the duplicate lines are not adjacent, uniq does not work, so you need to use sort to remove the duplicate lines.

Exercise: Use uniq and sort to remove non-adjacent duplicate lines

The tr command replaces characters in standard input

echo "hello,fissure" | tr 'az' 'AZ' #Convert lowercase to uppercase

vim text editor

Vim is a convenient editor and a powerful tool for program development and script writing.

Vim is divided into three modes: command mode, input mode, bottom edge mode

The minimum installation does not have the vim package, we need to install

sudo apt-get install vim-gtk #Ubuntu
yum install vim -y #CentOS

After successful installation, we enter the command vim day03.txt

At this point we have entered command mode. In this state, you cannot enter input. You can pass commands to vim, a or i to switch to input mode

When we type the colon : in command mode, we enter the bottom edge mode. In bottom edge mode, q means exit the program, w means save the file, and wq means exit the program. Add an exclamation mark after the above commands! Enforcement on behalf of

Common shortcut keys in vim command mode

Ctrl+f Move the screen down one page

Ctrl+b Move the screen up one page

home or 0 moves to the first character of a line

end or $ Move to the last character of this line

G Move to the last line

gg Move to the first line

Number + G moves to the next line

Move the number down a few lines

/string Search string string

yy copy the current line

dd deletes the current line

u Undo the last action

p Paste from the next line

P Paste from the previous line

Summarize

The above is the introduction of Linux common text processing commands and vim text editor. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!
If you find this article helpful, please feel free to reprint it and please indicate the source. Thank you!

You may also be interested in:
  • Summary of Linux vi command knowledge points and usage
  • Linux Vim Practical Commands Explained
  • Detailed explanation of the usage of common Linux commands (Part 2) ———— Text editor commands vi/vim
  • Detailed explanation of Docker service command (summary)
  • Detailed explanation of running multiple commands in Docker container (supervisor)
  • Detailed examples of using macro commands in Vim
  • Vim command collection
  • Common commands for using the text editor vi in ​​Linux
  • Detailed summary of Linux file editing command vi
  • Summary of commonly used commands of Vim editor
  • Recover the missing "View in Browser" command in Visual Studio 2017
  • Detailed explanation of the differences and commands between vi and vim
  • Linux vim editing command mode
  • Complete list of Vim split screen commands
  • vim command list
  • How to turn Vim into a Python IDE with two commands
  • Detailed explanation of vi commands in Linux
  • The most complete collection of VI commands and shortcut keys. Recommended collection

<<:  Solve the problem of blocking positioning DDL in MySQL 5.7

>>:  Ideas and codes for implementing Vuex data persistence

Recommend

Analysis and practice of React server-side rendering principle

Most people have heard of the concept of server-s...

JavaScript function detailed introduction

Any number of statements can be encapsulated thro...

Implementation steps for enabling docker remote service link on cloud centos

Here we introduce the centos server with docker i...

Implementing a simple student information management system based on VUE

Table of contents 1. Main functions 2. Implementa...

Summary of MySQL date and time functions (MySQL 5.X)

1. MySQL gets the current date and time function ...

Summary of MySQL slow log practice

Slow log query function The main function of slow...

Detailed explanation of using split command to split Linux files

A few simple Linux commands let you split and rea...

Detailed explanation of the steps to create a web server with node.js

Preface It is very simple to create a server in n...

MySQL master-slave synchronization principle and application

Table of contents 1. Master-slave synchronization...

Detailed explanation of Vue mixin usage and option merging

Table of contents 1. Use in components 2. Option ...

How to uninstall and reinstall Tomcat (with pictures and text)

Uninstall tomcat9 1. Since the installation of To...

JS implements a simple counter

Use HTML CSS and JavaScript to implement a simple...

How to configure Nginx domain name rewriting and wildcard domain name resolution

This article introduces how to configure Nginx to...

Detailed explanation of overflow:auto usage

Before starting the main text, I will introduce s...