gpt4 book ai didi

linux - 我可以在 linux 中用定界符解析文件后对字段进行子字符串化吗

转载 作者:太空宇宙 更新时间:2023-11-04 10:03:35 25 4
gpt4 key购买 nike

例如

这是数据

45|019|6|113|201901101522|40000539306|
45|015|1|6|201901101045|40000707530|
45|018|6|201|201901101733|40002235304|
45|009|8|377|201901101732|40002097431|

我想看到这样的

2019011
2019011
2019011
2019011
2019011

这是我已经尝试过的:cut -d'|' -f5 < input.txt这些是我得到的

201901101522
201901101045
201901101733
201901101732

最佳答案

您可以再次将其通过管道传输到 cut 中:

cut -d'|' -f5 <input.txt | cut -c1-7

或者使用awk:

awk -F'\|' '{print substr($5, 1, 7)}' input.txt

关于linux - 我可以在 linux 中用定界符解析文件后对字段进行子字符串化吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54223101/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com