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

Mini Program to Implement the Complete Shopping Cart

The mini program implements a complete shopping c...

Analysis and solution of a.getAttribute(href,2) problem in IE6/7

Brief description <br />In IE6 and 7, in a ...

MySQL Practical Experience of Using Insert Statement

Table of contents 1. Several syntaxes of Insert 1...

How to install MySQL server community version MySQL 5.7.22 winx64 in win10

Download: http://dev.mysql.com/downloads/mysql/ U...

Docker installation and configuration steps for Redis image

Table of contents Preface environment Install Cre...

Use and optimization of MySQL COUNT function

Table of contents What does the COUNT function do...

MySQL 5.6 binary installation process under Linux

1.1 Download the binary installation package wget...

JavaScript imitates Taobao magnifying glass effect

This article shares the specific code for JavaScr...

How to implement the prototype pattern in JavaScript

Overview The prototype pattern refers to the type...

When is it appropriate to use dl, dt, and dd?

dl:Definition list Definition List dt:Definition t...

Vue3 Vue Event Handling Guide

Table of contents 1. Basic event handling 2. Send...

Detailed introduction to Mysql date query

Query the current date SELECT CURRENT_DATE(); SEL...

Detailed explanation of Linux netstat command

Table of contents Linux netstat command 1. Detail...