In the study of Linux system, we want to see the file, generally on the cat command execution, the execution of large files, it is not good to make;
Less and more can achieve your dream, can help you to view the large file content,
More commands:
[Email protected] ~]# more/etc/man_db.conf
#
#
# This file was used by the MAN-DB package to configure, the man and cat paths.
# It is also used to provide a manpath for those without one by examining
# their PATH environment variable. For details see the Manpath (5) Mans page.
#
SPACEBAR: Represents a PAGE Down
Enter: Represents a downward line
/string: Represents the keyword in this display that queries the word "string" down
: F: Displays the file name immediately and the number of rows currently displayed;
Q: The delegate immediately leaves more, not displaying the text content.
B: The representative pages back.
Less command:
The use of LESSD is more flexible than more, in more we can not move forward, only look back, and then automatically exit, the man command is called less command to achieve
[Email protected] ~]# less/etc/rc.d/init.d/functions
SPACEBAR: Flip one PAGE Down
K: Turn down a line
J: Turn up one line
/string: Query Down
? String: Query up
N: Forward
N: Reverse
Q: Leave
Text intercept content head and tail commands
Head [-N number] File
-N: followed by a number, representing a few lines of meaning
[Email protected] ~]# HEAD/ETC/PASSWD
Root:x:0:0:root:/root:/bin/bash
Bin:x:1:1:bin:/bin:/sbin/nologin
Daemon:x:2:2:daemon:/sbin:/sbin/nologin
The default is 10 rows, which are displayed.
[Email protected] ~]# head-n 20/etc/man_db.conf
This is showing 20 rows
Tail Command:
tail [-N number] File
-N: followed by a number representing the meaning of the following lines
-F: Indicates continuous detection of the file name after the next, to CTRL-C will end tail detection
[Email protected] ~]# TAIL/ETC/PASSWD
Qemu:x:107:107:qemu User:/:/sbin/nologin
Chrony:x:990:985::/var/lib/chrony:/sbin/nologin
When we do not follow the number, the default output from the end of the file 10 lines,
You can do this if you want to see the last 3 lines of the file.
[Email protected] ~]# tail-n 3/etc/passwd
Ntp:x:38:38::/etc/ntp:/sbin/nologin
Tcpdump:x:72:72::/:/sbin/nologin
Aliyun:x:1000:1000:aliyun:/home/aliyun:/bin/bash
Cut command: Cut the character segment of the text to achieve the results you want
Cut [OPTION] ... [FILE] ...
-D DELIMITER: Indicates delimiter, default tab
-F Fileds:
#: Section # Fields
#,#[,#]: Discrete multiple fields, such as 1,3,6
#-#: Multiple consecutive fields, such as 1-6
Mixed use: 1-3,7
-C cut by character
--output-delimiter=string specifying the output delimiter
Example: Find the UID in the/etc/passwd file; First we analyze, we can use a colon: as a delimiter, so we can separate 7 fields, and then we take out the 3rd field, that is, the UID;
[[email protected] ~]# cut-d:-F 3 </etc/passwd
0
1
2
When removing paragraph 3,4,7, it should be expressed as such;-D:-f3,4,7
[Email protected] ~]# CAT/ETC/PASSWD | Cut-d:-f3,4,7
0:0:/bin/bash
1:1:/sbin/nologin
2:2:/sbin/nologin
Remove 3,567 consecutive, can be used. -D:-F 3,5-7
[Email protected] ~]# CAT/ETC/PASSWD | Cut-d:-f3,5-7
0:root:/root:/bin/bash
1:bin:/bin:/sbin/nologin
If cut by character: Indicates the number of characters from the line, the front, to the first
[[email protected] ~]# Cat txt
123456789
123456789
123456789
[[email protected] ~]# Cat txt | Cut-c 5
Replace the symbol, and change the middle of the pick to the * number
[Email protected] ~]# cut-d:-f3,4--output-delimiter=* </etc/passwd
0*0
1*1
2*2
Paste (merge two files with row number columns to one line)
-D: Delimiter: Specify delimiter, default tab
-S: All rows are composited on a single line display
Paste F1 F2
Paste-s F1 F2
[[email protected] ~]# paste-d "+"-s txt txt1
123456789+ 123456789+ 123456789
121121212121+232323232323+44444444444455+66666666677777
Indicates that the delimiter is "+" and then all lines of each file are composited in one row.
WC command: Collect text statistics (lines, bytes, words)
[Email protected] ~]# CAT/ETC/PASSWD | Wc-l
44 Rows
[Email protected] ~]# cat/etc/passwd |wc-w
89 words
[Email protected] ~]# CAT/ETC/PASSWD | Wc
44 89 2331
[Email protected] ~]# CAT/ETC/PASSWD | Wc-c
2331 bytes,
Sorting text Sort command:
Sort[options] File
-R: Performing the opposite direction
-N: Digital size
-F: Ignore character case in string
-u: Option to delete duplicate rows in output
-T C option uses C as the field bounding
The-k x option can be used multiple times using the C character Delimited X column collation
Uniq command: Remove duplicate front and back rows from input
uniq [option] ... [File] ...
-C: Shows the number of occurrences per line
-D: Show only rows that have been repeated
-U: Displays only rows that have not been duplicated, continuous and identical as duplicates
Commonly used with the sort command:
Sort Userlist.txt | Uniq-c
[[email protected] ~]# Sort-r txt | Uniq-c
4 ssssss
1 eeeeee
1 dddddd
4 AAAAAA
Diff command compares the differences of two files;
[[email protected] ~]# diff-u F1 f2 > Diff.log hit a patch output to diff. Log file
[Email protected] ~]# rm-f F2
[Email protected] ~]# Patch-b F1 diff.log
Patching file F1
[Email protected] ~]# MV F1.orig F1
[Email protected] ~]#
[Email protected] ~]# MV F1 F2
Linux Text Processing tool explained