gpt4 book ai didi

linux - 找到模式后 Grep for 2 words

转载 作者:太空宇宙 更新时间:2023-11-04 09:04:44 26 4
gpt4 key购买 nike

场景是我有一个文件并包含一个字符串“日期和时间是 2012-12-07 17:11:50”

我已经搜索并找到了一个命令

grep 'the date and time is' 2012-12-07.txt | cut -d\   -f5

它只显示第 5 个单词,我需要第 5 个和第 6 个的组合,所以我尝试了

grep 'the date and time is' 2012-12-07.txt | cut -d\   -f5 -f6 

但它的错误。

现在,如何用一个命令 grep 第 5 个和第 6 个单词

我只需要像 2012-12-07 17:11:50 这样的输出

最佳答案

你应该可以使用

$ grep 'the date and time is' 2012-12-07.txt | cut -d' ' -f6-7

检查 the man page -f 选项参数的语法。

关于linux - 找到模式后 Grep for 2 words,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13762783/

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