gpt4 book ai didi

linux - Unix 切割基于列中的顺序

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:44:03 25 4
gpt4 key购买 nike

我有一个返回如下内容的 bash 脚本:

/title
my_title
/year
2017

如何使用简单的剪切命令(或无法编写脚本的命令)提取年份(2017 年)?

我知道如果标题不存在,cut -d\-f2 会起作用...那么如何跳过标题并只获取年份?

最佳答案

$ sed -n '/\/year/{n;p;q}' infile
2017

这样做:

/\/year/ { # If the line matches "year"
n # Get next line
p # Print line
q # Quit: don't have to read the rest of the file
}

-n 确保不会打印任何其他内容。

关于linux - Unix 切割基于列中的顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34997723/

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