Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the commonly used text processing commands in Linux

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article is to share with you about the commonly used text processing commands in Linux, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.

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 the 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 rear via a "pipeline". |

Man ls | col-b > ls_help # Export the help document for the ls command

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

Cut-b # split in bytes cut-b "1 output-delimiter=' 3" # output first and third bytes cut-c # split in characters cut-d # define delimiter, use cut-f # with-d with-f, output field cut-output-delimiter=' delimiter'# replace the delimiter with your own delimiter

Wc Statistics Command

Wc-c # display bytes wc-l # display line number wc-w # display word count

Exercise: use the pipe characters wc statistics command and cut command to count the number of characters in the file and print them to the screen

Echo command, exportin

Echo-n # output without line wrapping

Head-n, the first n lines of viewing the file. Default is 10 lines.

Tail-n, n lines after viewing the file, default 10 lines

Exercise: use head and tail with pipe characters to output 10 to 15 lines of / var/log/message

Cat View File Information

More displays the file information in the form of one page, the space is the next page, and the b key will display it back to the next page.

Less, use less to browse files at will

Sort sorting

Sort-b # ignores the space character at the beginning of each line sort-c # checks whether the file is sorted in order sort-f # treats lowercase letters as uppercase letters sort-o output file # saves the results in the specified file sort-r # sorts sort-n # sorts the sort-t separator by numeric size # specifies the delimiter

Example:

Uniq removes duplicate lines

Example: (the previous number indicates how many times it has occurred)

Uniq does not work when duplicate rows are not adjacent, so you need to work with sort to remove duplicate lines

Exercise: use uniq,sort to remove non-adjacent duplicate lines

The tr command replaces characters entered by the standard

Echo "hello,fissure" | tr'amurz''AmurZ' # convert lowercase to uppercase

Vim text editor

Vim is a convenient editor, for program development, script writing is a sharp weapon.

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

There is no vim package for the minimum installation, we need to install it.

Sudo apt-get install vim-gtk # Ubuntuyum install vim- y # CentOS

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

At this point, we enter the command mode, which cannot be entered. We can pass the command for vim, and an or I can switch to input mode.

We hit the colon in the command mode: enter the bottom mode, Q to exit the program, w to save the file, wq to exit the program, the above command followed by an exclamation point! On behalf of enforcement

Common shortcut keys in vim command mode

Move the Ctrl+f screen down one page

Move the Ctrl+b screen up one page

Home or 0 move to the first character of the line

End or $move to the last character of the line

G moves to the last line

Gg moves to the first line

The number + G moves to which line

The number moves down a few lines

/ string lookup string string

Yy copies the current line

Dd deletes the current line

U restore the previous action

P paste from the next line

P paste from the previous line

What is Linux system Linux is a free-to-use and free-spread UNIX-like operating system, is a POSIX-based multi-user, multi-task, multi-threaded and multi-CPU operating system, using Linux can run major Unix tools, applications and network protocols.

These are the commonly used text processing commands in Linux, and the editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report