美文网首页
cut常用命令

cut常用命令

作者: dming1024 | 来源:发表于2019-05-04 20:38 被阅读0次

参考文章:
https://www.cnblogs.com/Spiro-K/p/6361646.html
cut一般用于对文档的切分,选取.
以一个实例进行展示cut的功能

 cat gdc_manifest_20190503_010922.txt |less -SN
      1 id      filename        md5     size    state
      2 3e48014d-ce4a-4937-bba4-13eaf631a64a    TCGA.OV.somaticsniper.3e48014d-ce4a-4937-bba4-13eaf631a64a.DR-10.0.somatic.maf.gz       2e
      3 51423d79-e9c5-4c4d-b12c-99c1338dbd43    TCGA.OV.muse.51423d79-e9c5-4c4d-b12c-99c1338dbd43.DR-10.0.somatic.maf.gz        fe3f8b0a78
      4 5296cf00-4d8c-4db3-80d7-930a4b44f90d    TCGA.HNSC.varscan.5296cf00-4d8c-4db3-80d7-930a4b44f90d.DR-10.0.somatic.maf.gz   d90fbd1392
      5 59a84472-27d4-497c-8f37-8bc447ff9374    TCGA.GBM.muse.59a84472-27d4-497c-8f37-8bc447ff9374.DR-10.0.somatic.maf.gz       c578956721
      6 5d5dfadb-f18d-4f19-aff4-166dac7b92df    TCGA.CHOL.somaticsniper.5d5dfadb-f18d-4f19-aff4-166dac7b92df.DR-10.0.somatic.maf.gz     09
      7 64e23e2f-ec04-4f6b-82b3-375e2d49804b    TCGA.PCPG.mutect.64e23e2f-ec04-4f6b-82b3-375e2d49804b.DR-10.0.somatic.maf.gz    853d50fa89
      8 6c93f518-1956-4435-9806-37185266d248    TCGA.BRCA.varscan.6c93f518-1956-4435-9806-37185266d248.DR-10.0.somatic.maf.gz   23f303806e
      9 76313658-c6df-4f73-8e04-affdbb0013bd    TCGA.LGG.somaticsniper.76313658-c6df-4f73-8e04-affdbb0013bd.DR-10.0.somatic.maf.gz      16
     10 7837f512-39c2-4c7c-a338-43e51a54701c    TCGA.CHOL.muse.7837f512-39c2-4c7c-a338-43e51a54701c.DR-10.0.somatic.maf.gz

选取第一列

 cat gdc_manifest_20190503_010922.txt |cut -f1
id
3e48014d-ce4a-4937-bba4-13eaf631a64a
51423d79-e9c5-4c4d-b12c-99c1338dbd43
5296cf00-4d8c-4db3-80d7-930a4b44f90d
59a84472-27d4-497c-8f37-8bc447ff9374
5d5dfadb-f18d-4f19-aff4-166dac7b92df
64e23e2f-ec04-4f6b-82b3-375e2d49804b
6c93f518-1956-4435-9806-37185266d248
76313658-c6df-4f73-8e04-affdbb0013bd
7837f512-39c2-4c7c-a338-43e51a54701c
81ac2c46-37db-4dcd-923a-061a7ae626a3
995c0111-d90b-4140-bee7-3845436c3b42
a8f41106-633d-4027-9e1f-e73bfd48f11e
aa5eb12e-6074-442a-9ff8-281b921e7d96
b22b85eb-2ca8-4c9f-a1cd-b77caab999bd
bd3cdd86-a5ce-43dc-92b2-9c2c3105d1df
c3df46a9-85d1-45d4-954a-825313d4a26d
cc207fe8-ee0a-4b65-82cb-c8197d264126
d12371d7-18ff-4105-a4a0-59de52b82805
d3fa70be-520a-420e-bb6d-651aeee5cb50
e3ad739d-6baa-4c42-a6f7-786d069239c1

当然同样也可以用awk

cat gdc_manifest_20190503_010922.txt |awk '{print $1}'
id
3e48014d-ce4a-4937-bba4-13eaf631a64a
51423d79-e9c5-4c4d-b12c-99c1338dbd43
5296cf00-4d8c-4db3-80d7-930a4b44f90d
59a84472-27d4-497c-8f37-8bc447ff9374
5d5dfadb-f18d-4f19-aff4-166dac7b92df
64e23e2f-ec04-4f6b-82b3-375e2d49804b
6c93f518-1956-4435-9806-37185266d248
76313658-c6df-4f73-8e04-affdbb0013bd
7837f512-39c2-4c7c-a338-43e51a54701c
81ac2c46-37db-4dcd-923a-061a7ae626a3
995c0111-d90b-4140-bee7-3845436c3b42
a8f41106-633d-4027-9e1f-e73bfd48f11e
aa5eb12e-6074-442a-9ff8-281b921e7d96
b22b85eb-2ca8-4c9f-a1cd-b77caab999bd
bd3cdd86-a5ce-43dc-92b2-9c2c3105d1df
c3df46a9-85d1-45d4-954a-825313d4a26d
cc207fe8-ee0a-4b65-82cb-c8197d264126
d12371d7-18ff-4105-a4a0-59de52b82805
d3fa70be-520a-420e-bb6d-651aeee5cb50
e3ad739d-6baa-4c42-a6f7-786d069239c1

以“-”为分割符,选择第一列

 cat gdc_manifest_20190503_010922.txt |cut -f1|cut -d"-" -f1
id
3e48014d
51423d79
5296cf00
59a84472
5d5dfadb
64e23e2f
6c93f518
76313658
7837f512
81ac2c46
995c0111
a8f41106
aa5eb12e
b22b85eb
bd3cdd86
c3df46a9
cc207fe8
d12371d7
d3fa70be
e3ad739d

以“-”为分割符,选择第2,3列

cat gdc_manifest_20190503_010922.txt |cut -f1|cut -d"-" -f2,3

id
ce4a-4937
e9c5-4c4d
4d8c-4db3
27d4-497c
f18d-4f19
ec04-4f6b
1956-4435
c6df-4f73
39c2-4c7c
37db-4dcd
d90b-4140
633d-4027
6074-442a
2ca8-4c9f
a5ce-43dc
85d1-45d4
ee0a-4b65
18ff-4105
520a-420e
6baa-4c42

在之前的基础上,选择第1-4个字符

cat gdc_manifest_20190503_010922.txt |cut -f1|cut -d"-" -f2,3|cut -c1-4

id
ce4a
e9c5
4d8c
27d4
f18d
ec04
1956
c6df
39c2
37db
d90b
633d
6074
2ca8
a5ce
85d1
ee0a
18ff
520a
6baa

相关文章

网友评论

      本文标题:cut常用命令

      本文链接:https://www.haomeiwen.com/subject/kjsfoqtx.html