linux按列分割cut
按列获取数据,例如ps命令中,我想获取UID这一列。使用ps | cut -c 44-47便可以。
Shell代码
$ ps
PID PPID PGID WINPID TTY UID STIME COMMAND
5204 1 5204 5204 con 500 11:53:47 /bin/sh
4716 5204 4716 2724 con 500 11:54:05 /bin/ps
www.zhishiwu.com
Shell代码
$ ps | cut -c 44-47
UID
500
500
500
cut有几个常用参数,-c 指定开始字符位置, -b 指定开始字节位置, -f 指定开始分割节点位置。
cut --help
Sehll代码
$ cut --help
Usage: cut [OPTION]... [FILE]...
Print selected parts of lines from each FILE to standard output.
-b, --bytes=LIST output only these bytes
-c, --characters=LIST output only these characters
-d, --delimiter=DELIM use DELIM instead of TAB for field delimiter
-f, --fields=LIST output only these fields
-n (ignored)
-s, --only-delimited do not print lines not containing delimiters
--output-delimiter=STRING use STRING as the output delimiter
the default is to use the input delimiter
--help display this help and exit
--version output version information and exit
www.zhishiwu.com
Use one, and only one of -b, -c or -f. Each LIST is made up of one
range, or many ranges separated by commas. Each range is one of:
N N'th byte, character or field, counted from 1
N- from N'th byte, character or field, to end of line
N-M from N'th to M'th (included) byte, character or field
-M from first to M'th (included) byte, character or field
With no FILE, or when FILE is -, read standard input.
Report bugs to <bug-textutils@gnu.org>.