字符串对象分割【cut】

cut -dchar -ffilednum

Cut one line into different fileds by char, and then print out the filednumth filed.

Blank and no blank are optional between -d and char or between -f and filednum.


cut -ccharnum

Print out the charnum char of one line.


filednum and charnum have the same formats as following:

N: indicate the Nth filed or char

N-: indicate the fileds or chars from the Nth filed or char to the end of this line

N-M: indicate the fileds or chars from the Nth filed or char to the Mth filed or char of this line

-N: indicate the fileds or chars from the first filed or char to the Nth filed or char of this line.

[nick@d01 bash]$ cat cut.txt
root:tree:1234
nick:leaf:4567
[nick@d01 bash]$ cut -d : -f 3 ./cut.txt
1234
4567
[nick@d01 bash]$ cut -d: -f-2 ./cut.txt
root:tree
nick:leaf
[nick@d01 bash]$ cut -d: -f2- ./cut.txt
tree:1234
leaf:4567
[nick@d01 bash]$ cut -c1-3 ./cut.txt
roo
nic
[nick@d01 bash]$ cut -c-3 ./cut.txt
roo
nic
[nick@d01 bash]$ cut -c3- ./cut.txt
ot:tree:1234
ck:leaf:4567

-d and -c are not permitted to use at the same time.

你可能感兴趣的:(字符串)