In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "what are the common text filtering commands in Linux". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn what are the common text filtering commands in Linux.
01 cat command
Usually used to display the contents of a text file
It is generally used to view short text files because of their limited buffer
The-s option can be used to merge extra blank lines in the file, and multiple blank lines will be compressed into a single blank line.
The-n option displays the line number
The-b option skips the number of blank lines and displays the line numbers of non-blank lines
Cat can be used to assign standard input to standard output without any parameters.
02 more command
Can be used to view the contents of a text file on a split screen.
When the contents of the file have been checked on one screen, it can be viewed separately, and the last line will show the prompt of more.
The enter key scrolls back one line and the space scrolls one screen.
Search is also supported in more, which is consistent with the search usage in vim
Press Q key to exit more automatically
You can add pipe symbols and more commands after some commands, and the results of the commands can be displayed on separate screens.
03 less command
Used to display the contents of a text file in separate screens
Less is more powerful than the more command
The enter key scrolls back one line and the space scrolls one screen.
You can also use the upper and lower keys to check, more cannot be rolled back
Search operations are also supported
More will exit automatically after displaying the contents of the file; less will not, you need to use the Q key.
In the process of viewing, you can also call other shell instructions, the same as the bottom line mode of vim
04 grep command
Is a long matching instruction that matches the text we enter and searches for matching lines in the file
# grep "root" / ets/passwd
Regular expressions are supported in matching patterns
# grep-n "fs$" / proc/filesystem / / search for lines ending in fs
05 head command
Used to display the high-quality content of the file, the first 10 lines of the file are displayed by default
# head / etc/httpd/conf/httpd.conf
The-n option specifies the number of rows displayed
It is important to display the high quality content of some very large files.
Can display high-quality content of multiple files
06 tail command
Used to display the tail content of a given text file, and the tail 10 lines are displayed by default
# tail filename
The-n option specifies the number of lines that are displayed
-f can dynamically follow the changes at the end of the file, and this option is often used to monitor system log files.
07 wc command
Used to count the number of lines, words and bytes in a text file
# wc / etc/passwd
44 72 2102 / etc/passwd
# wc-l / etc/passwd / / count the number of lines in a separate file
# ps-ef | grep gnome | wc-l / / Statistics on the number of gnome processes in the current system
# wc
Then enter part of the content, and press Ctrl+d to count the text information we just entered.
08 uniq command
Used to filter duplicate lines in the file without changing the contents of the file
Requires that the text to be filtered is already sorted
First use the sort command to sort, and then use the uniq command # sort file | uniq
The-c option can count the number of duplicate rows
09 cut command
Used to display the columns specified in the text file
# cut-f 1-d "" / etc/fstab / / split by spaces to show part 1
# cut-c-15 / proc/net/arp / / displays the first 15 characters of each column, that is, the IP address
10 sort command
Used to sort text
# sort file
Just sorting the content in file for output does not change the content of file.
The-o option can be exported to the specified file
# sort file-o result
You can also use the redirect function to save the sort results to a file
11 join command
Used to merge the same fields in a given file, requiring the file to be sorted
# cat math
Tom 90
Jim 91
# cat english
Jim 95
Tom 96
# sort math > math.sorted
# sort english > english.sorted
# join math.sorted english.sorted
Jim 91 95
Tom 90 96
12 split command
Used to divide a given file into several small files
# split acess_log
A lot of small files are generated, each of which defaults to 1000 lines
The-l option specifies the number of lines for the split file size
13 unexpand command
Used to convert extra space characters in a file into tabs
# cat test.txt
Liuli zhangsan
# unexpand-t 10 test.txt
Liuli zhangsan
-t converts the specified number of whitespace into a Tab key
14 tr command
Is a character processing tool that replaces and deletes individual characters in a given text, not a string processing tool
# tr dev xyz
The sed command can replace strings
# tr Amurz Amurz
# tr-d angi
Zhslswwu
# echo $PATH
/ opt/arm-2009q3/bin:/usr/lib/qt4/bin:/usr/lib/qt-3.3/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/beangr/bin
# echo $PATH | tr ":"\ n" / / replace the: in the result with a newline character
/ opt/arm-2009q3/bin
/ usr/lib/qt4/bin:/usr/lib/qt-3.3/bin
/ usr/local/bin
/ usr/bin
/ bin
/ usr/local/sbin
/ usr/sbin
/ sbin
/ home/beangr/bin
15 tee command
Used to read data from standard input, save it to a specified file, and output it to standard output
# cat / etc/fstab | tee file1 file2 file3
/ * Save to file1,file2,file3 while normal output to standard output * /
16 tac command
Used to display the contents of text in reverse order in units of behavior
Tac is a counter-instruction of cat
17 spell command
Is a spell check command in Linux that can check the spelling of the text in a file in terms of words and print out misspelled words
# spell file
18 paste command
Used for merging multiple text files to list as units
# cat t1.txt
Name math java
Tom 100 70
Jim 80 88
# cat t2.txt
C++
ninety
eighty-nine
# paste t1.txt t2.txt
Name math java C++
Tom 100 70 90
Jim 80 88 89
If you need to save the results to a file, you need to use redirection
19 diff command
Used to compare the differences between two files
# diff file1 file2
The diff command is often used to generate patch files.
# diff-Nur file1 file2 > a.patch
20 cmp command
Used to compare the types of two files, which can be any type of file
Will show where it starts to be different.
# cmp file1 file2
# cmp / bin/ls / bin/mail
# cmp file1 file1 / / compare two identical files with no output
21 look command
Used to display lines in a file that begin with a specified string, requiring that the text file be ordered
# cat t1.txt
Name math java
Zhang 100 70
Lisi 70 88
Wang 100 70
Zhang 100 70
# sort t1.txt > t1.txt.sorted
# look zhang t1.txt
Zhang 100 70
# look zhang t1.txt.sorted
Zhang 100 70
Zhang 100 70
# look hello / / you can query our dictionary and all words containing hello will be displayed.
When you install the look command, two dictionary files are installed
22 ispell command
You can check the Chinese and English spelling errors in the document and give tips for correction.
# cat test.txt
Yyear month hppy
# the result of ispell test.txt / / modification will be saved to a file
23 fold command
Used to control the width of the screen when the contents of the file are displayed
# fold-w 20 / etc/fstab / / specify a width of 20 characters
The content of the newline does not mean that the text is multi-line, it is just multi-line display.
24 fmt command
Used to optimize the text format of the contents of a text file
# fmt-u / etc/fstab / / will compress the displayed spaces
25 expand command
Used to convert tabs in a file to space characters
# cat t1.txt
Hello world
Hello Linux
# expand-t 20 t1.txt
Hello world
Hello Linux
Reciprocal with unexpand
26 col command
Control information used to filter the output of other instructions
# cat mytest | col > mytest3
27 colm command
Used to delete the specified column in the file (in characters)
# colm 20
The original content will not change.
# colm 20 50
28 comm command
Used to compare sorted files in behavioral units
# cat chengji1
Wangwu 90
Lisi 60
Zhangsan 80
# cat chengji2
Wangwu 90
Zhangsan 80
Lisi 70
# sort chengji1 > chengji1-1
# sort chengji2 > chengji2-2
# comm chengji1-1 chengji2-2
29 csplit command
Used to split a large file into small files in behavioral units
# csplit test.txt 300
/ * split into two files from 300 lines * /
30 diff3 command
Used to compare the differences of 3 files and show their differences
# diff3 file1 file2 file3
31 diffstat command
Used to count the output of diff instructions
# diff a.patch
32 printf command
Used to format and output the results to standard output, very similar to the printf function in C language
# printf "% s\ t% s\ n"Hello"world"
Hello world
33 pr command
Used to convert a text file into a file suitable for printing, you can divide the file into multiple pages and add a print title
# pr test.txt > test.txt.print
34 od command
An octal, hexadecimal, or other format encoded byte used in an output file, usually used to display characters that cannot be displayed directly on a terminal.
# od-tcx1 test.txt
# cat test.txt
Hello world
35 rev command
It is used to output the text content of the file in reverse order of characters in behavior units.
# cat test.txt
Hello world
I love linux!
# rev test.txt
Dlrow olleh
! xunil evol I
Thank you for your reading, these are the contents of "what are the common text filtering commands in Linux". After the study of this article, I believe you have a deeper understanding of what the common text filtering commands in Linux have, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.