bash – 另一种选择:cut -d?
发布时间:2020-12-16 01:52:51 所属栏目:安全 来源:网络整理
导读:当我输入ls时,我得到: aedes_aegypti_upstream_dremeready_all_simpleMasked_random.fastaanopheles_albimanus_upstream_dremeready_all_simpleMasked_random.fastaanopheles_arabiensis_upstream_dremeready_all_simpleMasked_random.fastaanopheles_steph
当我输入ls时,我得到:
aedes_aegypti_upstream_dremeready_all_simpleMasked_random.fasta anopheles_albimanus_upstream_dremeready_all_simpleMasked_random.fasta anopheles_arabiensis_upstream_dremeready_all_simpleMasked_random.fasta anopheles_stephensi_upstream_dremeready_all_simpleMasked_random.fasta culex_quinquefasciatus_upstream_dremeready_all_simpleMasked_random.fasta 我想将它管道切割(或通过一些替代方式),以便我只得到: aedes_aegypti anopheles_albimanus anopheles_arabiensis anopheles_stephensi culex_quinquefasciatus 如果cut会接受一个字符串(多个字符)作为它的分隔符,那么我可以使用: cut -d "_upstream_" -f1 但这是不允许的,因为剪切仅将单个字符作为分隔符. 解决方法
awk确实允许字符串作为分隔符:
$awk -F"_upstream_" '{print $1}' file aedes_aegypti anopheles_albimanus anopheles_arabiensis anopheles_stephensi culex_quinquefasciatus drosophila_melanogaster 注意对于给定的输入,您还可以使用带_作为分隔符的cut并打印前两个记录: $cut -d'_' -f-2 file aedes_aegypti anopheles_albimanus anopheles_arabiensis anopheles_stephensi culex_quinquefasciatus drosophila_melanogaster sed和grep也可以做到.例如,这个grep使用前瞻来打印从行开头的所有内容,直到找到_upstream: $grep -Po '^w*(?=_upstream)' file aedes_aegypti anopheles_albimanus anopheles_arabiensis anopheles_stephensi culex_quinquefasciatus drosophila_melanogaster (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |