Similar to awk Functions
Example 1
$ A = 'echo root: X: 0: 0: Root:/root:/bin/bash | cut-D: -F 1,5 'shuohailhl @ shuohailhl-PC/cygdrive/d $ echo $ aroot: Root
In the preceding example, the root: X: 0: 0: Root:/root:/bin/bash command is redirected to the cut command.-D indicates the delimiter. Here, the colon is used: as the separator,-F indicates the field, and 1st and 5th fields are selected,
Example 2: print only the first field
$ A = 'echo root: X: 0: 0: Root:/root:/bin/bash | cut-D: -F 1 'shuohailhl @ shuohailhl-PC/cygdrive/d $ echo $ aroot
Example 3: print all fields after the first field, including the first field
Shuohailhl @ shuohailhl-PC/cygdrive/d $ A = 'echo root: X: 0: 0: Root:/root:/bin/bash | cut-D: -F 1-'shuohailhl @ shuohailhl-PC/cygdrive/d $ echo $ aroot: X: 0: 0: Root:/root: /bin/bashshuohailhl @ shuohailhl-PC/cygdrive/d $ A = 'echo root: X: 0: 0: Root:/root:/bin/bash | cut-D: -F 3-'// print all fields following the 3rd fields, including the Third Field shuohailhl @ shuohailhl-PC/cygdrive/d $ echo $ A0: 0: Root: /root:/bin/bash
Example 4: capture 2nd to 4th Fields
Shuohailhl @ shuohailhl-PC/cygdrive/d $ A = 'echo root: X: 0: 0: Root:/root:/bin/bash | cut-D: -F 2-4 'shuohailhl @ shuohailhl-PC/cygdrive/d $ echo $ ax: 0: 0
Example 5: truncates a specified number of characters
Shuohailhl @ shuohailhl-PC/cygdrive/d $ A = 'echo root: X: 0: 0: Root:/root: /bin/bash | cut-C 2-5 '// intercept the string shuohailhl @ shuohailhl-PC/cygdrive/d $ echo $ aoot: shuohailhl @ shuohailhl-PC/cygdrive/d $ A = 'echo root: X: 0: 0: Root:/root: /bin/bash | cut-C 2-7' // intercept the string shuohailhl @ shuohailhl-PC/cygdrive/d $ echo $ aoot: X: shuohailhl @ shuohailhl-PC/cygdrive/d $ A = 'echo root: X: 0: 0: Root:/root: /bin/bash | cut-C-2 '// capture the first two characters shuohailhl @ shuohailhl-PC/cygdrive/d $ echo $ aroshuohailhl @ shuohailhl-PC/cygdrive/d $ = 'echo root: x: 0: 0: Root:/root: /bin/bash | cut-C 2-'// capture 2nd shuohailhl @ shuohailhl-PC/cygdrive/d $ echo $ aoot: X: 0: 0: Root: /root:/bin/bash
Example 6 specify the file. The last parameter is the file name.
$ Cat pass.txt root: X: 0: 0: Root:/root:/bin/bashbin: X: 1: 1: Bin:/bin:/sbin/nologindaemon: X: 2: 2: daemon:/sbin/nologinadm: X: 3: 4: ADM:/var/adm: /sbin/nologinshuohailhl @ shuohailhl-PC/cygdrive/d $ cut-D:-F 1-3. /pass.txt root: X: 0bin: X: 1 daemon: X: 2adm: X: 3