gpt4 book ai didi

bash - 如果值或两个连续的行与列不匹配,如何打印分隔符

转载 作者:行者123 更新时间:2023-11-29 09:01:20 25 4
gpt4 key购买 nike

我有如下输入,如果两行之间第三列的值不同,我需要在行之间放置一个分隔符。

one two three four
five six three seven
eight nine ten elevel
alpha beta ten gama
tango charlie oscar bla

预期结果:

one two three four
five six three seven
=
eight nine ten elevel
alpha beta ten gama
=
tango charlie oscar bla

这是我认为可行的方法,但实际上不行。

awk '{col3=$3;next} $3!=col3{$0="\n="$0;print $0}' input

最佳答案

$ awk '$3!=p && NR>1 { print "=" } { print; p=$3 }' file
one two three four
five six three seven
=
eight nine ten elevel
alpha beta ten gama
=
tango charlie oscar bla

关于bash - 如果值或两个连续的行与列不匹配,如何打印分隔符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48522125/

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