cut -d ' 分隔字符 ' -f fields
cut -c 字符区间
beyes@linux-beyes:~> echo $PATH
/usr/lib/mpi/gcc/openmpi/bin:/home/beyes/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/X11R6/bin:/usr/games:/opt/kde3/bin:/usr/lib/mit/bin:/usr/lib/mit/sbin
#找出上面蓝色加亮部分的路径并单独列出
beyes@linux-beyes:~> echo $PATH | cut -d ':' -f 4
/usr/bin
#另外,如果想同时列出第3和第5个路径,则如下
beyes@linux-beyes:~> echo $PATH | cut -d ':' -f 3,5
/usr/local/bin:/bin
beyes@linux-beyes:~> export
declare -x ALSA_CONFIG_PATH="/etc/alsa-pulse.conf"
declare -x COLORTERM="gnome-terminal"
declare -x CPU="i686"
declare -x CSHEDIT="emacs"
declare -x CVS_RSH="ssh"
.... .... ...
beyes@linux-beyes:~> export | cut -c 12-
ALSA_CONFIG_PATH="/etc/alsa-pulse.conf"
COLORTERM="gnome-terminal"
CPU="i686"
CSHEDIT="emacs"
CVS_RSH="ssh"
... ... ... ...
beyes@linux-beyes:~> export | cut -c 12-20
ALSA_CONF
COLORTERM
CPU="i686
CSHEDIT="
CVS_RSH="
... ... ... ...
beyes@linux-beyes:~> last
beyes pts/4 :0.0 Mon Jun 1 23:52 - 23:54 (00:01)
beyes pts/3 :0.0 Mon Jun 1 23:23 still logged in
beyes pts/3 :0.0 Mon Jun 1 00:22 - 00:35 (00:12)
beyes pts/1 :0.0 Mon Jun 1 00:19 still logged in
root pts/3 :1.0 Sun May 31 18:06 - 18:11 (00:04)
root pts/1 192.168.2.104 Sun May 31 18:05 - 18:42 (00:37)
... ... ... ...
beyes@linux-beyes:~> last | cut -d ' ' -f 1
beyes
beyes
beyes
beyes
root
root
# cat tmp.txt
No Name Mark Percent
1 Tom 38 80
2 Jim 58 10
3 Lee 48 30
4 Ken 58 40
# cut -f2 --complement tmp.txt
No Mark Percent
1 38 80
2 58 10
3 48 30
4 58 40
# cat temp.txt
abcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyz
# cut temp.txt -c1-3,6-9 --output-delimiter ":"
abc:fghi
abc:fghi
abc:fghi
abc:fghi
参数 | 说明 |
N | 第 N 个字节,字符或字段,从1开始计数 |
N- | 从第N个字节,字符或字段直至行尾 |
N-M | 从第N到第M(包括第M)个字节,字符或字段 |
-M | 从第 1 到第 M(包括第M)个字节,字符或字段 |
欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) | Powered by Discuz! X3.2 |