gpt4 book ai didi

linux - 怎么会出现 "squeeze-repeated"字样呢?

转载 作者:太空宇宙 更新时间:2023-11-04 05:04:48 24 4
gpt4 key购买 nike

如何“挤压重复”的单词?类似于“压缩重复字符”与 tr -s ''

我想更改例如:

hello.hello.hello.hello

hello

最佳答案

这可以是一种方式:

$ cat a
hello hello bye but bye yeah
hello yeah
$ awk 'BEGIN{OFS=FS=" "}
{ for (i=1; i<=NF; i++) {
if (!($i in a)) {printf "%s%s",$i,OFS; a[$i]=$i}
};
delete a;
print ""
}' a
hello bye but yeah
hello yeah

您可以更改字段分隔符:

$ cat a
hello|hello|bye|but|bye|yeah
hello|yeah
$ awk 'BEGIN{OFS=FS="|"} {for (i=1; i<=NF; i++) {if (!($i in a)) {printf "%s%s",$i,OFS; a[$i]=$i}}; delete a; print ""}' a
hello|bye|but|yeah|
hello|yeah|

关于linux - 怎么会出现 "squeeze-repeated"字样呢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19118225/

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