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 | 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 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! You may also be interested in:
|
<<: Solve the problem of blocking positioning DDL in MySQL 5.7
>>: Ideas and codes for implementing Vuex data persistence
Using c3p0 Import the c3p0jar package <!-- htt...
Most people have heard of the concept of server-s...
Any number of statements can be encapsulated thro...
Here we introduce the centos server with docker i...
Table of contents 1. Main functions 2. Implementa...
1. MySQL gets the current date and time function ...
Slow log query function The main function of slow...
A few simple Linux commands let you split and rea...
Preface It is very simple to create a server in n...
Table of contents 1. Master-slave synchronization...
Table of contents 1. Use in components 2. Option ...
Uninstall tomcat9 1. Since the installation of To...
Use HTML CSS and JavaScript to implement a simple...
This article introduces how to configure Nginx to...
Before starting the main text, I will introduce s...