Sometimes we often encounter such a problem: there is a page of the telephone number is thin, in order to write the rules of people's names, home addresses, telephone, notes, etc., at this time we just want to get everyone's name and their corresponding phone number, you have several ways to achieve it?
It is true that this vertical positioning is difficult to achieve by conventional means, at which point cut will be able to work.
What ' s cut?
Sub Yue: The Cut command extracts a text column from a text file or from a text stream.
Command usage:
Cut-b list [-n] [file ...]
CUT-C list [File ...]
Cut-f list [-D delim][-s][file ...]
Parameters:
-B,--bytes=list
Output these bytes
-C,--characters=list
Output these characters
-D,--delimiter=delim
Use Delim instead of TAB to make field (field) delimiters
-F,--fields=list
Output these fields
-N
Ignored
-S,--only-delimited
Do not show lines without delimiters
--output-delimiter=string
Using STRING as the output delimiter, the default (output delimiter) is the input separator
--help
Display Help information, and then end
--version
Display version information, and then end
Use and use only one of the options in-B,-C, or-F. The LIST consists of multiple ranges separated by a range (range) or comma. The scope is one of the following forms:
N
Nth Byte, character or field, counting from 1
N-
From Nth Byte, character or field up to end of line
N-m
From Nth to M (and including m) byte, character or field
-M
From 1th to M (and including m) byte, character or field
Read data from standard input if you do not specify file files, or.
Example:
The code is as follows:
[Root@localhost ~]# cat/etc/passwd | Cut-b 1 |head-5 #输出文件的第一个字节
R
B
D
A
L
The code is as follows:
[Root@localhost ~]# cat/etc/passwd | Cut-c 1-4 |head-5 #输出文件的前四个字符
Root
Bin
Daem
Adm:
Lp:x
The code is as follows:
[Root@localhost ~]# cat/etc/passwd | Cut-f1-d ': ' |head-5 #以: Split file, output first field
Root
Bin
Daemon
cd/
Lp
The code is as follows:
# Cat A.txt
SSSs affff dddd Fe FSC
RRR F ADFA EER DDD
The code is as follows:
# cat A.txt |cut-f1,3-d $ ' t ' #1, 3 columns
SSSs dddd
RRR ADFA