小编Mat*_*ler的帖子

Uniq 不会删除重复项

我正在使用以下命令

curl -silent http://api.openstreetmap.org/api/0.6/relation/2919627 http://api.openstreetmap.org/api/0.6/relation/2919628 | grep node | awk '{print $3}' | uniq
Run Code Online (Sandbox Code Playgroud)

当我想知道为什么uniq不删除重复项时。知道为什么吗?

command-line curl uniq

16
推荐指数
1
解决办法
2万
查看次数

Sed:每隔一个换行符替换一次模式?

有没有办法告诉sed在每第二次出现时替换模式?或者至少每隔一行?(当然可以使用脚本,但我问自己是否sed可以做到)。

编辑

我发现

sed -e "s/pattern/replacement/g;n"
Run Code Online (Sandbox Code Playgroud)

但它取代了每一次出现,而不是第二次。

例子

输入文件:

I have a pattern in each line
Also the second line has the pattern
Another pattern here
And -- you guess it -- a pattern
Run Code Online (Sandbox Code Playgroud)

期望的输出:

I have a pattern in each line
Also the second line has the replacement
Another pattern here
And -- you guess it -- a replacement
Run Code Online (Sandbox Code Playgroud)

sed replace

11
推荐指数
2
解决办法
4万
查看次数

标签 统计

command-line ×1

curl ×1

replace ×1

sed ×1

uniq ×1